mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Recursively deleting directories during state sync. (#189)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
|
||||
BIN
test/bin/hpfs
BIN
test/bin/hpfs
Binary file not shown.
Reference in New Issue
Block a user