Be more atomic during writing of files -- this prevents other processes from seeing empty or impartial files
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user