main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. // All rights reserved. Use of this source code is governed by an MIT-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "flag"
  7. "fmt"
  8. "log"
  9. "os"
  10. "github.com/syncthing/syncthing/files"
  11. "github.com/syncthing/syncthing/protocol"
  12. "github.com/syndtr/goleveldb/leveldb"
  13. )
  14. func main() {
  15. log.SetFlags(0)
  16. log.SetOutput(os.Stdout)
  17. repo := flag.String("repo", "default", "Repository ID")
  18. node := flag.String("node", "", "Node ID (blank for global)")
  19. flag.Parse()
  20. db, err := leveldb.OpenFile(flag.Arg(0), nil)
  21. if err != nil {
  22. log.Fatal(err)
  23. }
  24. fs := files.NewSet(*repo, db)
  25. if *node == "" {
  26. log.Printf("*** Global index for repo %q", *repo)
  27. fs.WithGlobalTruncated(func(fi protocol.FileIntf) bool {
  28. f := fi.(protocol.FileInfoTruncated)
  29. fmt.Println(f)
  30. fmt.Println("\t", fs.Availability(f.Name))
  31. return true
  32. })
  33. } else {
  34. n, err := protocol.NodeIDFromString(*node)
  35. if err != nil {
  36. log.Fatal(err)
  37. }
  38. log.Printf("*** Have index for repo %q node %q", *repo, n)
  39. fs.WithHaveTruncated(n, func(fi protocol.FileIntf) bool {
  40. f := fi.(protocol.FileInfoTruncated)
  41. fmt.Println(f)
  42. return true
  43. })
  44. }
  45. }