Create directory of database if it does not exist (#650)

* fix: create directory of database if it does not exist

* fix code quality issue
This commit is contained in:
1138-4EB 2019-02-03 15:51:17 +01:00 committed by Henrique Dias
parent 17b514510b
commit de205177f2
1 changed files with 10 additions and 8 deletions

View File

@ -62,18 +62,20 @@ type pythonData struct {
func dbExists(path string) (bool, error) { func dbExists(path string) (bool, error) {
stat, err := os.Stat(path) stat, err := os.Stat(path)
if err == nil {
return stat.Size() != 0, nil
}
if os.IsNotExist(err) { if os.IsNotExist(err) {
return false, nil d := filepath.Dir(path)
} else if err != nil { _, err = os.Stat(d)
return false, err if os.IsNotExist(err) {
os.MkdirAll(d, 0700)
return false, nil
}
} }
if stat.Size() == 0 { return false, err
return false, nil
}
return true, nil
} }
func python(fn pythonFunc, cfg pythonConfig) cobraFunc { func python(fn pythonFunc, cfg pythonConfig) cobraFunc {