From f0a4efb242a66c1ec34b1139e8853ab1795cfeea Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 22 Sep 2020 21:01:50 -0700 Subject: [PATCH] Attempt to create directory structure for config file if missing --- parser/parser.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index 334b8c6..9e00597 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -14,6 +14,7 @@ import ( "gopkg.in/yaml.v2" "io/ioutil" "os" + "path/filepath" "regexp" "strconv" "strings" @@ -169,8 +170,13 @@ func (f *ConfigurationFile) Parse(path string, internal bool) error { return nil } - if _, err := os.Create(path); err != nil { - return errors.WithStack(err) + b := strings.TrimSuffix(path, filepath.Base(path)) + if err := os.MkdirAll(b, 0755); err != nil { + return errors.Wrap(err, "failed to create base directory for missing configuration file") + } else { + if _, err := os.Create(path); err != nil { + return errors.Wrap(err, "failed to create missing configuration file") + } } return f.Parse(path, true)