mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 03:02:07 +03:00
Be more atomic during writing of files -- this prevents other processes from seeing empty or impartial files
This commit is contained in:
parent
0ce40fd46e
commit
859f1590dd
13
config.go
13
config.go
@ -108,11 +108,16 @@ func writeConfig() error {
|
||||
log.Printf("Couldn't generate YAML file: %s", err)
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(configfile, yamlText, 0644)
|
||||
err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644)
|
||||
if err != nil {
|
||||
log.Printf("Couldn't write YAML config: %s", err)
|
||||
return err
|
||||
}
|
||||
err = os.Rename(configfile+".tmp", configfile)
|
||||
if err != nil {
|
||||
log.Printf("Couldn't rename YAML config: %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -127,10 +132,14 @@ func writeCoreDNSConfig() error {
|
||||
log.Printf("Couldn't generate DNS config: %s", err)
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(corefile, []byte(configtext), 0644)
|
||||
err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644)
|
||||
if err != nil {
|
||||
log.Printf("Couldn't write DNS config: %s", err)
|
||||
}
|
||||
err = os.Rename(corefile+".tmp", corefile)
|
||||
if err != nil {
|
||||
log.Printf("Couldn't rename DNS config: %s", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -929,11 +929,17 @@ func writeFilterFile() error {
|
||||
data = append(data, []byte(rule)...)
|
||||
data = append(data, '\n')
|
||||
}
|
||||
err := ioutil.WriteFile(filterpath, data, 0644)
|
||||
err := ioutil.WriteFile(filterpath+".tmp", data, 0644)
|
||||
if err != nil {
|
||||
log.Printf("Couldn't write filter file: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.Rename(filterpath+".tmp", filterpath)
|
||||
if err != nil {
|
||||
log.Printf("Couldn't rename filter file: %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user