fix: create config folder if not exists
This commit is contained in:
		| @@ -3,6 +3,7 @@ package config | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"regexp" | ||||
| ) | ||||
|  | ||||
| @@ -31,9 +32,17 @@ func Read(configFile string) (*FluckyConfig, error) { | ||||
| // Write the configuration into a file, specified by the configuration filepath | ||||
| 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) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 		return fmt.Errorf("Can not write config file: %v", err) | ||||
| 	} | ||||
| 	defer f.Close() | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user