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 18d6f293f7
commit b0b93e3d50

View file

@ -196,6 +196,14 @@ func IsPathExist(path string) bool {
return true return true
} }
func mustSyncParentDirIfExists(path string) {
parentDirPath := filepath.Dir(path)
if !IsPathExist(parentDirPath) {
return
}
MustSyncPath(parentDirPath)
}
// MustRemoveAll removes path with all the contents. // MustRemoveAll removes path with all the contents.
// //
// It properly handles NFS issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/61 . // It properly handles NFS issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/61 .
@ -204,8 +212,7 @@ func MustRemoveAll(path string) {
if err == nil { if err == nil {
// 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.
parentDirPath := filepath.Dir(path) mustSyncParentDirIfExists(path)
MustSyncPath(parentDirPath)
return return
} }
if !isTemporaryNFSError(err) { if !isTemporaryNFSError(err) {
@ -245,8 +252,7 @@ func dirRemover() {
} }
// 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.
parentDirPath := filepath.Dir(path) mustSyncParentDirIfExists(path)
MustSyncPath(parentDirPath)
} }
} }