mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
419197ba08
commit
26f8d7ea1b
1 changed files with 10 additions and 4 deletions
14
lib/fs/fs.go
14
lib/fs/fs.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue