diff options
| author | Jeff Carr <[email protected]> | 2024-10-23 21:46:18 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-23 21:46:18 -0500 |
| commit | acdd6e9c5be6e2d60f6a8defbaccc2f9e09a421d (patch) | |
| tree | 92559f13ed9f75261e8a3ef338e2bf43a2386a11 /configfiles.go | |
| parent | 2df36637bf502f952ee0d2225459afbb9722949c (diff) | |
another check for custom cpu xml
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'configfiles.go')
| -rw-r--r-- | configfiles.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/configfiles.go b/configfiles.go index 5c2b0f6..4ea72e0 100644 --- a/configfiles.go +++ b/configfiles.go @@ -84,16 +84,37 @@ func readConfigFile(filename string) error { } func writeConfigFile() { + test := time.Now().Format("YYYYMMDD-HH-MM") + if !writeConfigFileTmp("virtigo.json.new." + test) { + log.Println("config file write error") + os.Exit(-1) + } + if !writeConfigFileTmp("virtigo.json") { + log.Println("config file write error") + os.Exit(-1) + } + + origname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json") + newname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json.old") + err := os.Rename(origname, newname) + if err != nil { + log.Printf("rename fail: %s", err) + os.Exit(-1) + } +} + +func writeConfigFileTmp(filename string) bool { fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json") cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666) defer cfgfile.Close() if err != nil { log.Info("open config file :", err) - return + return false } json := me.cluster.FormatJSON() fmt.Fprintln(cfgfile, json) log.Info("Write:", fullname, "OK") + return true } func writeConfigFileDroplets() { |
