diff options
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -5,8 +5,10 @@ package chatpb import ( "errors" + "fmt" "os" "path/filepath" + "time" "go.wit.com/lib/protobuf/bugpb" "go.wit.com/log" @@ -56,6 +58,21 @@ func (all *Chats) ConfigSave() error { } return err } + + // --- Backup Logic --- + filename := filepath.Join(os.Getenv("GEMINI_HOME"), "gemini.pb") + if _, err := os.Stat(filename); err == nil { + // File exists, so back it up. + dir := filepath.Dir(filename) + timestamp := time.Now().Format("20060102-150405") + backupFilename := fmt.Sprintf("gemini.%s.pb", timestamp) + backupPath := filepath.Join(dir, backupFilename) + if err := os.Rename(filename, backupPath); err != nil { + log.Warn("Could not backup config file:", err) + } + } + // --- End Backup Logic --- + if err := configWrite("gemini.pb", data); err != nil { log.Infof("chatpb.ConfigSave() failed len(Chats)=%d bytes=%d", len(cleanChats.Chats), len(data)) return err |
