Return configuration save failures

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-09 14:23:27 -04:00
committed by Brandon McGinty
parent 501943c8f7
commit c36305cb38
2 changed files with 27 additions and 9 deletions
+11 -9
View File
@@ -46,20 +46,22 @@ type eUser struct {
LocallyMuted bool // Changed from Muted to LocallyMuted to match User struct
}
func (c *Config) SaveConfig() {
var data []byte
// SaveConfig atomically replaces the persisted configuration. Errors are
// returned so an unavailable directory cannot crash the client.
func (c *Config) SaveConfig() error {
data, err := toml.Marshal(c.config)
if err != nil {
panic(err)
return err
}
err = ioutil.WriteFile(c.fn+".tmp", data, 0600)
if err != nil {
panic(err)
tmp := c.fn + ".tmp"
if err := ioutil.WriteFile(tmp, data, 0600); err != nil {
return err
}
err = os.Rename(c.fn+".tmp", c.fn)
if err != nil {
panic(err)
if err := os.Rename(tmp, c.fn); err != nil {
_ = os.Remove(tmp)
return err
}
return nil
}
func key(k uiterm.Key) *uiterm.Key {