[common] do not create {filePath}.bak in WriteFileAtomic
We use WriteFileAtomic in two places: ``` p2p/addrbook.go 338: err = cmn.WriteFileAtomic(filePath, jsonBytes, 0644) types/priv_validator.go 162: err = WriteFileAtomic(privVal.filePath, jsonBytes, 0600) ``` and we don't need .bak in any of the above. We save priv_validator every 10ms and addrbook every 2 min.
This commit is contained in:
parent
8a51210efc
commit
b25aa3b472
11
common/os.go
11
common/os.go
|
@ -96,17 +96,6 @@ func MustWriteFile(filePath string, contents []byte, mode os.FileMode) {
|
|||
// WriteFileAtomic writes newBytes to temp and atomically moves to filePath
|
||||
// when everything else succeeds.
|
||||
func WriteFileAtomic(filePath string, newBytes []byte, mode os.FileMode) error {
|
||||
// If a file already exists there, copy to filePath+".bak" (overwrite anything)
|
||||
if _, err := os.Stat(filePath); !os.IsNotExist(err) {
|
||||
fileBytes, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not read file %v. %v", filePath, err)
|
||||
}
|
||||
err = ioutil.WriteFile(filePath+".bak", fileBytes, mode)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not write file %v. %v", filePath+".bak", err)
|
||||
}
|
||||
}
|
||||
f, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue