From 0f4fe8296ae50b1951402e66c84bfe6de99f66bc Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Mon, 2 Dec 2024 08:41:09 -0500 Subject: [PATCH] chore(config): if the config dir doesn't exist, create it Signed-off-by: Huamin Chen --- pkg/config/config.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 0f1b653791..1025916018 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -118,7 +118,14 @@ func newConfig() (*Config, error) { s, err := os.Stat(absBaseDir) if os.IsNotExist(err) { - return nil, fmt.Errorf("config-dir %s does not exist", BaseDir) + // if the directory does not exist, create it + if err := os.MkdirAll(absBaseDir, 0755); err != nil { + return nil, fmt.Errorf("config-dir %s does not exist", BaseDir) + } + s, err = os.Stat(absBaseDir) + if err != nil { + return nil, fmt.Errorf("failed to stat config-dir %s: %w", BaseDir, err) + } } if !s.IsDir() { return nil, fmt.Errorf("config-dir %s is not a directory", BaseDir)