Merge pull request #294 from ncdc/mkdir-p

Create the config directory in case it's missing
pull/302/head
Steve Kriss 2018-02-02 13:07:45 -08:00 committed by GitHub
commit 11f2be6254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -61,6 +61,12 @@ func LoadConfig() (map[string]string, error) {
func SaveConfig(config map[string]string) error {
fileName := configFileName()
// Try to make the directory in case it doesn't exist
dir := filepath.Dir(fileName)
if err := os.MkdirAll(dir, 0755); err != nil {
return errors.WithStack(err)
}
configFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755)
if err != nil {
return errors.WithStack(err)