Recursively deleting directories during state sync. (#189)

This commit is contained in:
Chalith Desaman
2020-12-09 13:43:34 +05:30
committed by GitHub
parent 0bc53fe23c
commit b86efb2d9b
4 changed files with 16 additions and 1 deletions

View File

@@ -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;

View File

@@ -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<std::string> &collection, std::string_view str, std::string_view delimeter)
{
if (str.empty())

View File

@@ -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<std::string> &collection, std::string_view str, std::string_view delimeter);
int stoull(const std::string &str, uint64_t &result);

Binary file not shown.