diff --git a/src/state/state_sync.cpp b/src/state/state_sync.cpp index ac3fa111..d5c88e1a 100644 --- a/src/state/state_sync.cpp +++ b/src/state/state_sync.cpp @@ -374,7 +374,7 @@ namespace state_sync std::string child_physical_path = std::string(ctx.hpfs_mount_dir).append(child_vpath); if ((ex_entry.is_file && unlink(child_physical_path.c_str()) == -1) || - !ex_entry.is_file && rmdir(child_physical_path.c_str()) == -1) + !ex_entry.is_file && util::remove_directory_recursively(child_physical_path.c_str()) == -1) return -1; LOG_DEBUG << "State sync: Deleted " << (ex_entry.is_file ? "file" : "dir") << " path " << child_vpath; diff --git a/src/util/util.cpp b/src/util/util.cpp index 49635f9e..9607ff9d 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -314,6 +314,19 @@ namespace util 1, FTW_PHYS); } + /** + * Remove a directory recursively with it's content. FTW_DEPTH is provided so all of the files and subdirectories within + * The path will be processed. FTW_PHYS is provided so symbolic links won't be followed. + */ + int remove_directory_recursively(std::string_view dir_path) + { + return nftw( + dir_path.data(), [](const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { + return remove(fpath); + }, + 1, FTW_DEPTH | FTW_PHYS); + } + void split_string(std::vector &collection, std::string_view str, std::string_view delimeter) { if (str.empty()) diff --git a/src/util/util.hpp b/src/util/util.hpp index 034c7000..9c26e1cd 100644 --- a/src/util/util.hpp +++ b/src/util/util.hpp @@ -74,6 +74,8 @@ namespace util int clear_directory(std::string_view dir_path); + int remove_directory_recursively(std::string_view dir_path); + void split_string(std::vector &collection, std::string_view str, std::string_view delimeter); int stoull(const std::string &str, uint64_t &result); diff --git a/test/bin/hpfs b/test/bin/hpfs index 825a07a6..4e87d70a 100755 Binary files a/test/bin/hpfs and b/test/bin/hpfs differ