fix: allow to start filebrowser with an existing but empty DB

This commit is contained in:
1138-4EB 2019-01-09 22:30:39 +01:00
parent bafe9f0ad7
commit 3ab3bfee58
2 changed files with 14 additions and 5 deletions

View File

@ -214,6 +214,9 @@ func setupLog(logMethod string) {
}
func quickSetup(flags *pflag.FlagSet, d pythonData) {
log.Println("Executing quick setup...")
set := &settings.Settings{
Key: generateRandomBytes(64), // 256 bit
Signup: false,

View File

@ -67,7 +67,7 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
data := pythonData{hadDB: true}
path := getParam(cmd.Flags(), "database")
_, err := os.Stat(path)
fd, err := os.Stat(path)
if os.IsNotExist(err) {
data.hadDB = false
@ -75,10 +75,16 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
if !cfg.noDB && !cfg.allowNoDB {
log.Fatal(path + " does not exist. Please run 'filebrowser config init' first.")
}
} else if err != nil {
panic(err)
} else if err == nil && cfg.noDB {
log.Fatal(path + " already exists")
} else if err == nil {
if cfg.noDB {
log.Fatal(path + " already exists")
}
if fd.Size() == 0 {
log.Println("Database file is empty")
data.hadDB = false
}
} else {
log.Fatal(err)
}
db, err := storm.Open(path)