poc: when deleting a file automatically adjust the current disk space being tracked in the cache

This commit is contained in:
Dane Everitt 2020-08-22 22:56:44 -07:00
parent c73a53dbe3
commit 1e39487240
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -616,6 +616,19 @@ func (fs *Filesystem) Delete(p string) error {
return errors.New("cannot delete root server directory")
}
if st, err := os.Stat(resolved); err != nil {
if !os.IsNotExist(err) {
fs.Server.Log().WithField("error", err).WithField("path", resolved).Warn("error while attempting to stat file before deletion")
}
} else {
// TODO: handle deleting a directory by finding its current size.
go func (st os.FileInfo) {
if !st.IsDir() {
atomic.SwapInt64(&fs.diskUsage, fs.diskUsage - st.Size())
}
}(st)
}
return os.RemoveAll(resolved)
}