Attempt to create directory structure for config file if missing

This commit is contained in:
Dane Everitt 2020-09-22 21:01:50 -07:00
parent 342c3ea565
commit f0a4efb242
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -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
}
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.WithStack(err)
return errors.Wrap(err, "failed to create missing configuration file")
}
}
return f.Parse(path, true)