Handle deleting a directory

This commit is contained in:
Dane Everitt 2020-08-23 14:34:42 -07:00
parent 37fbae0fcd
commit 3b33e803e3
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -621,12 +621,15 @@ func (fs *Filesystem) Delete(p string) error {
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())
atomic.SwapInt64(&fs.diskUsage, -st.Size())
} else {
go func(st os.FileInfo, resolved string) {
if s, err := fs.DirectorySize(resolved); err == nil {
atomic.AddInt64(&fs.diskUsage, -s)
}
}(st, resolved)
}
}(st)
}
return os.RemoveAll(resolved)