lib/fs: sync parent dir in MustRemoveAll only if it exists

The parent directory may be non-existing when the deleted directory
didn't exist before the MustRemoveAll call
This commit is contained in:
Aliaksandr Valialkin 2019-06-12 02:14:38 +03:00
parent 419197ba08
commit 26f8d7ea1b

View file

@ -196,6 +196,14 @@ func IsPathExist(path string) bool {
return true
}
func mustSyncParentDirIfExists(path string) {
parentDirPath := filepath.Dir(path)
if !IsPathExist(parentDirPath) {
return
}
MustSyncPath(parentDirPath)
}
// MustRemoveAll removes path with all the contents.
//
// It properly handles NFS issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/61 .
@ -204,8 +212,7 @@ func MustRemoveAll(path string) {
if err == nil {
// Make sure the parent directory doesn't contain references
// to the current directory.
parentDirPath := filepath.Dir(path)
MustSyncPath(parentDirPath)
mustSyncParentDirIfExists(path)
return
}
if !isTemporaryNFSError(err) {
@ -245,8 +252,7 @@ func dirRemover() {
}
// Make sure the parent directory doesn't contain references
// to the current directory.
parentDirPath := filepath.Dir(path)
MustSyncPath(parentDirPath)
mustSyncParentDirIfExists(path)
}
}