From b0b93e3d50d0a9e18fa62cf6bdc49c002cb61833 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 12 Jun 2019 02:14:38 +0300 Subject: [PATCH] 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 --- lib/fs/fs.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/fs/fs.go b/lib/fs/fs.go index 9f03285fd3..8c8501ba88 100644 --- a/lib/fs/fs.go +++ b/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) } }