From 21dc9bb7592d2db3c351293e0ec79c391490de30 Mon Sep 17 00:00:00 2001 From: b5 Date: Mon, 10 Sep 2018 17:23:14 -0400 Subject: [PATCH] check error before defer-removing disk usage file --- flatfs.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flatfs.go b/flatfs.go index 54bb2f3..cea61bd 100644 --- a/flatfs.go +++ b/flatfs.go @@ -863,6 +863,11 @@ 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 { @@ -870,10 +875,6 @@ func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) { _ = os.Remove(tmp.Name()) } }() - if err != nil { - log.Warningf("cound not write disk usage: %v", err) - return - } toWrite := fs.storedValue toWrite.DiskUsage = du