From de205177f26d7c09010fc47076b385a57f666a9b Mon Sep 17 00:00:00 2001 From: 1138-4EB <1138-4EB@users.noreply.github.com> Date: Sun, 3 Feb 2019 15:51:17 +0100 Subject: [PATCH] Create directory of database if it does not exist (#650) * fix: create directory of database if it does not exist * fix code quality issue --- cmd/utils.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/utils.go b/cmd/utils.go index 65a3884e..72f0177c 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -62,18 +62,20 @@ type pythonData struct { func dbExists(path string) (bool, error) { stat, err := os.Stat(path) + if err == nil { + return stat.Size() != 0, nil + } if os.IsNotExist(err) { - return false, nil - } else if err != nil { - return false, err + d := filepath.Dir(path) + _, err = os.Stat(d) + if os.IsNotExist(err) { + os.MkdirAll(d, 0700) + return false, nil + } } - if stat.Size() == 0 { - return false, nil - } - - return true, nil + return false, err } func python(fn pythonFunc, cfg pythonConfig) cobraFunc {