WriteToFile serializes the config to yaml and writes it out to a file. If not present, it creates the file with the mode 0600. If it is present it stomps the contents
(config clientcmdapi.Config, filename string)
| 403 | // WriteToFile serializes the config to yaml and writes it out to a file. If not present, it creates the file with the mode 0600. If it is present |
| 404 | // it stomps the contents |
| 405 | func WriteToFile(config clientcmdapi.Config, filename string) error { |
| 406 | content, err := Write(config) |
| 407 | if err != nil { |
| 408 | return err |
| 409 | } |
| 410 | dir := filepath.Dir(filename) |
| 411 | if _, err := os.Stat(dir); os.IsNotExist(err) { |
| 412 | if err = os.MkdirAll(dir, 0755); err != nil { |
| 413 | return err |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | if err := ioutil.WriteFile(filename, content, 0600); err != nil { |
| 418 | return err |
| 419 | } |
| 420 | return nil |
| 421 | } |
| 422 | |
| 423 | func lockFile(filename string) error { |
| 424 | // TODO: find a way to do this with actual file locks. Will |