Fix a potential file leak

Previously, if a write or sync error occurred, we would not have called
Close(). This commit refactors ReplaceFile() so that we are sure to call
Close(), and also attempts to delete the temporary file if errors occur.
This commit is contained in:
Michael Taufen
2017-09-14 09:23:30 -07:00
parent 16670f1a95
commit 62fecfb0f4
4 changed files with 40 additions and 12 deletions

View File

@@ -31,6 +31,7 @@ type Filesystem interface {
MkdirAll(path string, perm os.FileMode) error
Chtimes(name string, atime time.Time, mtime time.Time) error
RemoveAll(path string) error
Remove(name string) error
// from "io/ioutil"
ReadFile(filename string) ([]byte, error)