Skip to content

Commit

Permalink
check error before defer-removing disk usage file
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Sep 10, 2018
1 parent d25f80d commit 5a21fc1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions flatfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,16 +864,17 @@ func (fs *Datastore) checkpointLoop() {
func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) {
tmp, err := ioutil.TempFile(fs.path, "du-")
removed := false
if err != nil {
log.Warningf("cound not write disk usage: %v", err)
return
}

defer func() {
if !removed {
// silence errcheck
_ = os.Remove(tmp.Name())
}
}()
if err != nil {
log.Warningf("cound not write disk usage: %v", err)
return
}

toWrite := fs.storedValue
toWrite.DiskUsage = du
Expand Down

0 comments on commit 5a21fc1

Please sign in to comment.