main.go 1.0 KB

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 http://mozilla.org/MPL/2.0/.
  6. package main
  7. import (
  8. "flag"
  9. "fmt"
  10. "log"
  11. "os"
  12. "path/filepath"
  13. "github.com/syndtr/goleveldb/leveldb"
  14. "github.com/syndtr/goleveldb/leveldb/opt"
  15. )
  16. func main() {
  17. var mode string
  18. log.SetFlags(0)
  19. log.SetOutput(os.Stdout)
  20. flag.StringVar(&mode, "mode", "dump", "Mode of operation: dump, dumpsize")
  21. flag.Parse()
  22. path := flag.Arg(0)
  23. if path == "" {
  24. path = filepath.Join(defaultConfigDir(), "index-v0.11.0.db")
  25. }
  26. fmt.Println("Path:", path)
  27. ldb, err := leveldb.OpenFile(path, &opt.Options{
  28. ErrorIfMissing: true,
  29. Strict: opt.StrictAll,
  30. OpenFilesCacheCapacity: 100,
  31. })
  32. if err != nil {
  33. log.Fatal(err)
  34. }
  35. if mode == "dump" {
  36. dump(ldb)
  37. } else if mode == "dumpsize" {
  38. dumpsize(ldb)
  39. } else {
  40. fmt.Println("Unknown mode")
  41. }
  42. }