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) { func quickSetup(flags *pflag.FlagSet, d pythonData) {
log.Println("Executing quick setup...")
set := &settings.Settings{ set := &settings.Settings{
Key: generateRandomBytes(64), // 256 bit Key: generateRandomBytes(64), // 256 bit
Signup: false, Signup: false,

View File

@ -67,7 +67,7 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
data := pythonData{hadDB: true} data := pythonData{hadDB: true}
path := getParam(cmd.Flags(), "database") path := getParam(cmd.Flags(), "database")
_, err := os.Stat(path) fd, err := os.Stat(path)
if os.IsNotExist(err) { if os.IsNotExist(err) {
data.hadDB = false data.hadDB = false
@ -75,11 +75,17 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
if !cfg.noDB && !cfg.allowNoDB { if !cfg.noDB && !cfg.allowNoDB {
log.Fatal(path + " does not exist. Please run 'filebrowser config init' first.") log.Fatal(path + " does not exist. Please run 'filebrowser config init' first.")
} }
} else if err != nil { } else if err == nil {
panic(err) if cfg.noDB {
} else if err == nil && cfg.noDB {
log.Fatal(path + " already exists") 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) db, err := storm.Open(path)
checkErr(err) checkErr(err)