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 21dc9bb
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 @@ -863,17 +863,18 @@ func (fs *Datastore) checkpointLoop() {

func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) {
tmp, err := ioutil.TempFile(fs.path, "du-")
if err != nil {
log.Warningf("cound not write disk usage: %v", err)
return
}

removed := false
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 21dc9bb

Please sign in to comment.