Make delete more synchronous
This commit is contained in:
parent
9b7c0fb7f3
commit
ee460686d6
|
@ -321,6 +321,7 @@ func (fs *Filesystem) Copy(p string) error {
|
||||||
// Deletes a file or folder from the system. Prevents the user from accidentally
|
// Deletes a file or folder from the system. Prevents the user from accidentally
|
||||||
// (or maliciously) removing their root server data directory.
|
// (or maliciously) removing their root server data directory.
|
||||||
func (fs *Filesystem) Delete(p string) error {
|
func (fs *Filesystem) Delete(p string) error {
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
// This is one of the few (only?) places in the codebase where we're explicitly not using
|
// This is one of the few (only?) places in the codebase where we're explicitly not using
|
||||||
// the SafePath functionality when working with user provided input. If we did, you would
|
// the SafePath functionality when working with user provided input. If we did, you would
|
||||||
// not be able to delete a file that is a symlink pointing to a location outside of the data
|
// not be able to delete a file that is a symlink pointing to a location outside of the data
|
||||||
|
@ -348,14 +349,18 @@ func (fs *Filesystem) Delete(p string) error {
|
||||||
if !st.IsDir() {
|
if !st.IsDir() {
|
||||||
fs.addDisk(-st.Size())
|
fs.addDisk(-st.Size())
|
||||||
} else {
|
} else {
|
||||||
go func(st os.FileInfo, resolved string) {
|
wg.Add(1)
|
||||||
|
go func(wg *sync.WaitGroup, st os.FileInfo, resolved string) {
|
||||||
|
defer wg.Done()
|
||||||
if s, err := fs.DirectorySize(resolved); err == nil {
|
if s, err := fs.DirectorySize(resolved); err == nil {
|
||||||
fs.addDisk(-s)
|
fs.addDisk(-s)
|
||||||
}
|
}
|
||||||
}(st, resolved)
|
}(&wg, st, resolved)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
return os.RemoveAll(resolved)
|
return os.RemoveAll(resolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user