Files
syncthing/cmd/stindex/main.go
T

64 lines
1.1 KiB
Go
Raw Normal View History

2014-11-16 21:13:20 +01:00
// Copyright (C) 2014 The Syncthing Authors.
2014-09-29 21:43:32 +02:00
//
2015-03-07 21:36:35 +01:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
2014-07-06 14:46:48 +02:00
package main
import (
"flag"
"fmt"
"log"
"os"
2015-10-23 20:02:38 +01:00
"path/filepath"
2014-07-06 14:46:48 +02:00
"github.com/syncthing/syncthing/lib/db/backend"
2014-07-06 14:46:48 +02:00
)
func main() {
2015-10-23 20:02:38 +01:00
var mode string
2014-07-06 14:46:48 +02:00
log.SetFlags(0)
log.SetOutput(os.Stdout)
flag.StringVar(&mode, "mode", "dump", "Mode of operation: dump, dumpsize, idxck")
2015-10-23 20:02:38 +01:00
2014-07-06 14:46:48 +02:00
flag.Parse()
2015-10-23 20:02:38 +01:00
path := flag.Arg(0)
if path == "" {
path = filepath.Join(defaultConfigDir(), "index-v0.14.0.db")
2015-10-23 20:02:38 +01:00
}
var ldb backend.Backend
var err error
if looksLikeBadger(path) {
ldb, err = backend.OpenBadger(path)
} else {
ldb, err = backend.OpenLevelDBRO(path)
}
2014-07-06 14:46:48 +02:00
if err != nil {
log.Fatal(err)
}
switch mode {
case "dump":
2015-10-23 20:02:38 +01:00
dump(ldb)
case "dumpsize":
2015-10-23 20:21:21 +01:00
dumpsize(ldb)
case "idxck":
if !idxck(ldb) {
os.Exit(1)
}
case "account":
account(ldb)
default:
2015-10-23 20:02:38 +01:00
fmt.Println("Unknown mode")
2014-07-06 14:46:48 +02:00
}
}
func looksLikeBadger(path string) bool {
_, err := os.Stat(filepath.Join(path, "KEYREGISTRY"))
return err == nil
}