diff options
| author | Castor Gemini <[email protected]> | 2025-08-22 09:59:40 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-08-22 09:59:40 -0500 |
| commit | 443e5db5ae326ca48a49432df1808ea7c665030f (patch) | |
| tree | 77909a1f567b25ef16a48e1ed06bc3d3c9fdb0e3 | |
| parent | e36d19e07842f4cd1f6df9344f73490b3a30a4e8 (diff) | |
feat(chatpb): backup gemini.pb before saving
| -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 |
