lib/fs: do not pass done callback to tryRemoveAll() func

This improves code readability a bit.

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1313
This commit is contained in:
Aliaksandr Valialkin 2021-05-24 04:51:54 +03:00
parent 402a8ca710
commit 745eda9e87

View file

@ -11,7 +11,8 @@ import (
) )
func mustRemoveAll(path string, done func()) { func mustRemoveAll(path string, done func()) {
if tryRemoveAll(path, done) { if tryRemoveAll(path) {
done()
return return
} }
select { select {
@ -27,7 +28,8 @@ func mustRemoveAll(path string, done func()) {
}() }()
for { for {
time.Sleep(time.Second) time.Sleep(time.Second)
if tryRemoveAll(path, done) { if tryRemoveAll(path) {
done()
return return
} }
} }
@ -36,13 +38,12 @@ func mustRemoveAll(path string, done func()) {
var dirRemoverWG syncwg.WaitGroup var dirRemoverWG syncwg.WaitGroup
func tryRemoveAll(path string, done func()) bool { func tryRemoveAll(path string) bool {
err := os.RemoveAll(path) err := os.RemoveAll(path)
if err == nil || isStaleNFSFileHandleError(err) { if err == nil || isStaleNFSFileHandleError(err) {
// Make sure the parent directory doesn't contain references // Make sure the parent directory doesn't contain references
// to the current directory. // to the current directory.
mustSyncParentDirIfExists(path) mustSyncParentDirIfExists(path)
done()
return true return true
} }
if !isTemporaryNFSError(err) { if !isTemporaryNFSError(err) {