Skip to content
Snippets Groups Projects
Commit 668b28c2 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

fileutils: use std::filesystem::remove_all, check for error

Change-Id: I46a4563e24f3a427931be886b726a585fe823eff
parent 21cbcfef
No related branches found
No related tags found
No related merge requests found
...@@ -328,18 +328,24 @@ remove(const std::filesystem::path& path, bool erase) ...@@ -328,18 +328,24 @@ remove(const std::filesystem::path& path, bool erase)
return !RemoveDirectory(dhtnet::to_wstring(path.string()).c_str()); return !RemoveDirectory(dhtnet::to_wstring(path.string()).c_str());
#endif #endif
return std::remove(path.string().c_str()); std::error_code ec;
std::filesystem::remove(path, ec);
return ec.value();
} }
int int
removeAll(const std::filesystem::path& path, bool erase) removeAll(const std::filesystem::path& path, bool erase)
{ {
std::error_code ec;
if (not erase) {
std::filesystem::remove_all(path, ec);
return ec.value();
}
if (path.empty()) if (path.empty())
return -1; return -1;
auto status = std::filesystem::status(path); auto status = std::filesystem::status(path, ec);
if (std::filesystem::is_directory(status) and not std::filesystem::is_symlink(status)) { if (!ec && std::filesystem::is_directory(status) and not std::filesystem::is_symlink(status)) {
std::error_code ec;
for (const auto& entry: std::filesystem::directory_iterator(path, ec)) { for (const auto& entry: std::filesystem::directory_iterator(path, ec)) {
removeAll(entry.path(), erase); removeAll(entry.path(), erase);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment