diff options
| author | Jeff Carr <[email protected]> | 2025-09-03 01:23:01 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-03 01:23:01 -0500 |
| commit | 60ef1deb90eafd1741f231ddbc19f48b6199061b (patch) | |
| tree | 6b97f4a8ff730097f4ef54750703078421acfef9 /config.go | |
| parent | 1aaa1d0e0743acc62b41e65b7547a53de5a399bf (diff) | |
make something to save the books.pbv0.0.9v0.0.8v0.0.7v0.0.6v0.0.5v0.0.17v0.0.16v0.0.15v0.0.14v0.0.13v0.0.12v0.0.11v0.0.10
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -10,6 +10,7 @@ import ( "path/filepath" "time" + "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/bugpb" "go.wit.com/log" ) @@ -25,6 +26,7 @@ func (all *Chats) ConfigSave() error { log.Warn("chatpb all == nil") return errors.New("chatpb.ConfigSave() all == nil") } + log.Info("DOING ConfigSave()") // --- Start of Fix --- // Create a new, clean Chats object to avoid marshaling a slice with nil entries. @@ -46,7 +48,7 @@ func (all *Chats) ConfigSave() error { if err != nil { log.Info("chatpb proto.Marshal() failed len", len(data), err) // The tryValidate logic might be less necessary now but kept for safety. - if err := all.tryValidate(); err != nil { + if err := cleanChats.tryValidate(); err != nil { return err } else { data, err = cleanChats.Marshal() // Retry with the clean object @@ -61,6 +63,19 @@ func (all *Chats) ConfigSave() error { // --- Backup Logic --- filename := filepath.Join(os.Getenv("REGEX_HOME"), "regex.pb") + filebackup := filepath.Join(os.Getenv("REGEX_HOME"), "regex.backup.pb") + if s, err := os.Stat(filebackup); err == nil { + log.Info("STAT OF CONFIG BACKUP WORKED", filebackup) + age := time.Since(s.ModTime()) + if age > 10*time.Second { + log.Info(filebackup, "is greater than 10 minutes") + shell.RunVerbose([]string{"cp", filename, filebackup}) + } else { + log.Info(filebackup, "is less than 10 minutes") + } + } else { + log.Info("STAT OF CONFIG BACKUP FAILED", filebackup) + } if _, err := os.Stat(filename); err == nil { // File exists, so back it up. dir := filepath.Dir(filename) @@ -83,7 +98,6 @@ func (all *Chats) ConfigSave() error { } func (all *Chats) tryValidate() error { - err := bugpb.ValidateProtoUTF8(all) if err != nil { log.Printf("Protobuf UTF-8 validation failed: %v\n", err) @@ -169,15 +183,6 @@ func configWrite(filename string, data []byte) error { log.Warn("open config file :", err) return err } - if filename == "regex.text" { - // add header - cfgfile.Write([]byte("# this file is automatically re-generated from regex.pb, however,\n")) - cfgfile.Write([]byte("# if you want to edit it by hand, you can:\n")) - cfgfile.Write([]byte("# stop regex; remove regex.pb; edit regex.text; start regex\n")) - cfgfile.Write([]byte("# this will cause the default behavior to fallback to parsing this file for the config\n")) - cfgfile.Write([]byte("\n")) - cfgfile.Write([]byte("# this file is intended to be used to customize settings on what\n")) - } cfgfile.Write(data) return nil } |
