main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/calmh/syncthing/files"
  11. "github.com/calmh/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.WithGlobal(func(f protocol.FileInfo) bool {
  28. fmt.Println(f)
  29. fmt.Println("\t", fs.Availability(f.Name))
  30. return true
  31. })
  32. } else {
  33. n, err := protocol.NodeIDFromString(*node)
  34. if err != nil {
  35. log.Fatal(err)
  36. }
  37. log.Printf("*** Have index for repo %q node %q", *repo, n)
  38. fs.WithHave(n, func(f protocol.FileInfo) bool {
  39. fmt.Println(f)
  40. return true
  41. })
  42. }
  43. }