poc: when deleting a file automatically adjust the current disk space being tracked in the cache
This commit is contained in:
parent
c73a53dbe3
commit
1e39487240
|
@ -616,6 +616,19 @@ func (fs *Filesystem) Delete(p string) error {
|
||||||
return errors.New("cannot delete root server directory")
|
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)
|
return os.RemoveAll(resolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user