main.go 923 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. if mode == "dump" {
  30. dump(ldb)
  31. } else if mode == "dumpsize" {
  32. dumpsize(ldb)
  33. } else if mode == "idxck" {
  34. if !idxck(ldb) {
  35. os.Exit(1)
  36. }
  37. } else {
  38. fmt.Println("Unknown mode")
  39. }
  40. }