Commit a63d692f authored by Steven Allen's avatar Steven Allen

fix: ensure that we close the diskusage file, even if we fail to rename it

parent 2284a522
...@@ -973,11 +973,16 @@ func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) { ...@@ -973,11 +973,16 @@ func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) {
} }
removed := false removed := false
closed := false
defer func() { defer func() {
if !closed {
_ = tmp.Close()
}
if !removed { if !removed {
// silence errcheck // silence errcheck
_ = os.Remove(tmp.Name()) _ = os.Remove(tmp.Name())
} }
}() }()
toWrite := fs.storedValue toWrite := fs.storedValue
...@@ -999,6 +1004,7 @@ func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) { ...@@ -999,6 +1004,7 @@ func (fs *Datastore) writeDiskUsageFile(du int64, doSync bool) {
log.Warnw("cound not write disk usage", "error", err) log.Warnw("cound not write disk usage", "error", err)
return return
} }
closed = true
if err := os.Rename(tmp.Name(), filepath.Join(fs.path, DiskUsageFile)); err != nil { if err := os.Rename(tmp.Name(), filepath.Join(fs.path, DiskUsageFile)); err != nil {
log.Warnw("cound not write disk usage", "error", err) 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