Create complete parent dir structure when saving config to file

This commit is contained in:
fabianofranz 2015-04-16 14:17:54 -03:00
parent 6c394e4d81
commit f71aa6ad38

View File

@ -233,6 +233,12 @@ func WriteToFile(config clientcmdapi.Config, filename string) error {
if err != nil {
return err
}
dir := filepath.Dir(filename)
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err = os.MkdirAll(dir, 0755); err != nil {
return err
}
}
if err := ioutil.WriteFile(filename, content, 0600); err != nil {
return err
}