Unverified Commit 8e4cd220 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #72 from ipfs/fix/ensure-close-diskusage

fix: ensure that we close the diskusage file, even if we fail to rename it
parents 2284a522 a63d692f
......@@ -973,11 +973,16 @@ func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) {
}
removed := false
closed := false
defer func() {
if !closed {
_ = tmp.Close()
}
if !removed {
// silence errcheck
_ = os.Remove(tmp.Name())
}
}()
toWrite := fs.storedValue
......@@ -999,6 +1004,7 @@ func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) {
log.Warnw("cound not write disk usage", "error", err)
return
}
closed = true
if err := os.Rename(tmp.Name(), filepath.Join(fs.path, DiskUsageFile)); err != nil {
log.Warnw("cound not write disk usage", "error", err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment