[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:
Anton Kaliaev 2017-07-28 11:26:04 -04:00
parent 8a51210efc
commit b25aa3b472
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
1 changed files with 0 additions and 11 deletions

View File

@ -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