mirror of
https://github.com/Hopiu/micro.git
synced 2026-05-12 16:53:09 +00:00
settings: Perform write process safe
This commit is contained in:
parent
63d68ec441
commit
c926649496
1 changed files with 9 additions and 3 deletions
|
|
@ -155,6 +155,10 @@ var (
|
|||
VolatileSettings map[string]bool
|
||||
)
|
||||
|
||||
func writeFile(name string, txt []byte) error {
|
||||
return util.SafeWrite(name, txt, false)
|
||||
}
|
||||
|
||||
func init() {
|
||||
ModifiedSettings = make(map[string]bool)
|
||||
VolatileSettings = make(map[string]bool)
|
||||
|
|
@ -355,7 +359,8 @@ func WriteSettings(filename string) error {
|
|||
}
|
||||
|
||||
txt, _ := json.MarshalIndent(parsedSettings, "", " ")
|
||||
err = os.WriteFile(filename, append(txt, '\n'), util.FileMode)
|
||||
txt = append(txt, '\n')
|
||||
err = writeFile(filename, txt)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
@ -376,8 +381,9 @@ func OverwriteSettings(filename string) error {
|
|||
}
|
||||
}
|
||||
|
||||
txt, _ := json.MarshalIndent(settings, "", " ")
|
||||
err = os.WriteFile(filename, append(txt, '\n'), util.FileMode)
|
||||
txt, _ := json.MarshalIndent(parsedSettings, "", " ")
|
||||
txt = append(txt, '\n')
|
||||
err = writeFile(filename, txt)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue