main.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package main
  16. import (
  17. "flag"
  18. "fmt"
  19. "log"
  20. "os"
  21. "github.com/syncthing/syncthing/internal/files"
  22. "github.com/syncthing/syncthing/internal/protocol"
  23. "github.com/syndtr/goleveldb/leveldb"
  24. )
  25. func main() {
  26. log.SetFlags(0)
  27. log.SetOutput(os.Stdout)
  28. folder := flag.String("folder", "default", "Folder ID")
  29. device := flag.String("device", "", "Device ID (blank for global)")
  30. flag.Parse()
  31. db, err := leveldb.OpenFile(flag.Arg(0), nil)
  32. if err != nil {
  33. log.Fatal(err)
  34. }
  35. fs := files.NewSet(*folder, db)
  36. if *device == "" {
  37. log.Printf("*** Global index for folder %q", *folder)
  38. fs.WithGlobalTruncated(func(fi files.FileIntf) bool {
  39. f := fi.(protocol.FileInfoTruncated)
  40. fmt.Println(f)
  41. fmt.Println("\t", fs.Availability(f.Name))
  42. return true
  43. })
  44. } else {
  45. n, err := protocol.DeviceIDFromString(*device)
  46. if err != nil {
  47. log.Fatal(err)
  48. }
  49. log.Printf("*** Have index for folder %q device %q", *folder, n)
  50. fs.WithHaveTruncated(n, func(fi files.FileIntf) bool {
  51. f := fi.(protocol.FileInfoTruncated)
  52. fmt.Println(f)
  53. return true
  54. })
  55. }
  56. }