feat(chatpb): backup gemini.pb before saving
This commit is contained in:
parent
e36d19e078
commit
443e5db5ae
17
config.go
17
config.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue