fix: create config folder if not exists
This commit is contained in:
parent
82e82952ed
commit
48b18b61ec
@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,9 +32,17 @@ func Read(configFile string) (*FluckyConfig, error) {
|
|||||||
// Write the configuration into a file, specified by the configuration filepath
|
// Write the configuration into a file, specified by the configuration filepath
|
||||||
func Write(cfg *FluckyConfig, configFile string) error {
|
func Write(cfg *FluckyConfig, configFile string) error {
|
||||||
|
|
||||||
|
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||||
|
configDir := filepath.Dir(configFile)
|
||||||
|
err := os.MkdirAll(configDir, os.ModeDir)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Can not create config directory %v: %v", configDir, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
f, err := os.Create(configFile)
|
f, err := os.Create(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("Can not write config file: %v", err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user