Atomically update cached values file
This commit is contained in:
parent
cc5107d0db
commit
601a333b0e
2 changed files with 2 additions and 1 deletions
|
|
@ -24,6 +24,7 @@ func AtomicWriteFile(path string, data []byte, perm os.FileMode) (err error) {
|
|||
f.Close()
|
||||
if !removed {
|
||||
os.Remove(f.Name())
|
||||
removed = true
|
||||
}
|
||||
}()
|
||||
_, err = f.Write(data)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func (self *CachedValues[T]) Load() T {
|
|||
func (self *CachedValues[T]) Save() {
|
||||
raw, err := json.Marshal(self.Opts)
|
||||
if err == nil {
|
||||
os.WriteFile(self.Path(), raw, 0600)
|
||||
AtomicUpdateFile(self.Path(), raw, 0o600)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue