Fix #277: Periodically write config file while app is running

This commit is contained in:
Drew Weymouth
2023-11-10 08:58:09 -08:00
parent 68c05dd99a
commit 9f157e0aed
3 changed files with 36 additions and 0 deletions
+8
View File
@@ -2,6 +2,7 @@ package backend
import (
"os"
"sync"
"github.com/google/uuid"
"github.com/pelletier/go-toml/v2"
@@ -206,7 +207,14 @@ func ReadConfigFile(filepath, appVersionTag string) (*Config, error) {
return c, nil
}
var writeLock sync.Mutex
func (c *Config) WriteConfigFile(filepath string) error {
if !writeLock.TryLock() {
return nil // another write in progress
}
defer writeLock.Unlock()
b, err := toml.Marshal(c)
if err != nil {
return err