main.go 935 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package main
  7. import (
  8. "flag"
  9. "fmt"
  10. "log"
  11. "os"
  12. "path/filepath"
  13. "github.com/syncthing/syncthing/lib/db/backend"
  14. )
  15. func main() {
  16. var mode string
  17. log.SetFlags(0)
  18. log.SetOutput(os.Stdout)
  19. flag.StringVar(&mode, "mode", "dump", "Mode of operation: dump, dumpsize, idxck")
  20. flag.Parse()
  21. path := flag.Arg(0)
  22. if path == "" {
  23. path = filepath.Join(defaultConfigDir(), "index-v0.14.0.db")
  24. }
  25. ldb, err := backend.OpenLevelDBRO(path)
  26. if err != nil {
  27. log.Fatal(err)
  28. }
  29. switch mode {
  30. case "dump":
  31. dump(ldb)
  32. case "dumpsize":
  33. dumpsize(ldb)
  34. case "idxck":
  35. if !idxck(ldb) {
  36. os.Exit(1)
  37. }
  38. case "account":
  39. account(ldb)
  40. default:
  41. fmt.Println("Unknown mode")
  42. }
  43. }