From b2cd8e1fe8dbfc073339cff9b505c74e5af23a26 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Fri, 2 Feb 2018 16:01:52 -0500 Subject: [PATCH] Create the config directory in case it's missing Always try to create the config directory when saving the client config in case it doesn't exist. Signed-off-by: Andy Goldstein --- pkg/client/config.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/client/config.go b/pkg/client/config.go index 8f5d428b5..b5ec760a6 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -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)