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

@@ -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())