writeYAML serialises cfg to path atomically (tmp file + rename).
(path string, cfg *config.Config)
| 193 | |
| 194 | // writeYAML serialises cfg to path atomically (tmp file + rename). |
| 195 | func writeYAML(path string, cfg *config.Config) error { |
| 196 | tmp := path + ".tmp" |
| 197 | f, err := os.Create(tmp) |
| 198 | if err != nil { |
| 199 | return err |
| 200 | } |
| 201 | enc := yaml.NewEncoder(f) |
| 202 | enc.SetIndent(2) |
| 203 | if err := enc.Encode(cfg); err != nil { |
| 204 | f.Close() |
| 205 | os.Remove(tmp) |
| 206 | return err |
| 207 | } |
| 208 | enc.Close() |
| 209 | f.Close() |
| 210 | return os.Rename(tmp, path) |
| 211 | } |
no test coverage detected