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

fileutils: catch exceptions in removeAll

Change-Id: Ia0c3c975961bf96c6db80ed8f5c7b45bdee7e9cb
parent b1bf24c6
Branches
No related tags found
No related merge requests found
......@@ -336,21 +336,26 @@ remove(const std::filesystem::path& path, bool erase)
int
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())
return -1;
auto status = std::filesystem::status(path, ec);
if (!ec && std::filesystem::is_directory(status) and not std::filesystem::is_symlink(status)) {
for (const auto& entry: std::filesystem::directory_iterator(path, ec)) {
removeAll(entry.path(), erase);
try {
std::error_code ec;
if (not erase) {
std::filesystem::remove_all(path, ec);
return ec.value();
}
if (path.empty())
return -1;
auto status = std::filesystem::status(path, ec);
if (!ec && std::filesystem::is_directory(status) and not std::filesystem::is_symlink(status)) {
for (const auto& entry: std::filesystem::directory_iterator(path, ec)) {
removeAll(entry.path(), erase);
}
}
return remove(path, erase);
} catch (const std::exception& e) {
//JAMI_ERR("Error while removing %s: %s", path.c_str(), e.what());
return -1;
}
return remove(path, erase);
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment