Browse Source

[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.
pull/1842/head
Anton Kaliaev 8 years ago
parent
commit
b25aa3b472
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 0 additions and 11 deletions
  1. +0
    -11
      common/os.go

+ 0
- 11
common/os.go 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 // WriteFileAtomic writes newBytes to temp and atomically moves to filePath
// when everything else succeeds. // when everything else succeeds.
func WriteFileAtomic(filePath string, newBytes []byte, mode os.FileMode) error { 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("", "") f, err := ioutil.TempFile("", "")
if err != nil { if err != nil {
return err return err


Loading…
Cancel
Save