cmd/stindex: Detect and open Badger databases

This commit is contained in:
Jakob Borg 2020-05-30 09:47:11 +02:00
parent 94beed5c10
commit 1eea076f5c

View File

@ -30,7 +30,13 @@ func main() {
path = filepath.Join(defaultConfigDir(), "index-v0.14.0.db")
}
ldb, err := backend.OpenLevelDBRO(path)
var ldb backend.Backend
var err error
if looksLikeBadger(path) {
ldb, err = backend.OpenBadger(path)
} else {
ldb, err = backend.OpenLevelDBRO(path)
}
if err != nil {
log.Fatal(err)
}
@ -50,3 +56,8 @@ func main() {
fmt.Println("Unknown mode")
}
}
func looksLikeBadger(path string) bool {
_, err := os.Stat(filepath.Join(path, "KEYREGISTRY"))
return err == nil
}