Return immediatly from fs::remove_all on failure to remove entries

This way error code will be reflected properly
This commit is contained in:
Eladash 2019-08-11 13:05:11 +03:00 committed by Ivan
parent 0a5b6ad928
commit d48d424b19
2 changed files with 13 additions and 5 deletions

View File

@ -1539,7 +1539,7 @@ const std::string& fs::get_cache_dir()
return s_dir; return s_dir;
} }
void fs::remove_all(const std::string& path, bool remove_root) bool fs::remove_all(const std::string& path, bool remove_root)
{ {
for (const auto& entry : dir(path)) for (const auto& entry : dir(path))
{ {
@ -1550,19 +1550,27 @@ void fs::remove_all(const std::string& path, bool remove_root)
if (entry.is_directory == false) if (entry.is_directory == false)
{ {
remove_file(path + '/' + entry.name); if (!remove_file(path + '/' + entry.name))
{
return false;
}
} }
if (entry.is_directory == true) if (entry.is_directory == true)
{ {
remove_all(path + '/' + entry.name); if (!remove_all(path + '/' + entry.name))
{
return false;
}
} }
} }
if (remove_root) if (remove_root)
{ {
remove_dir(path); return remove_dir(path);
} }
return true;
} }
u64 fs::get_dir_size(const std::string& path) u64 fs::get_dir_size(const std::string& path)

View File

@ -503,7 +503,7 @@ namespace fs
const std::string& get_cache_dir(); const std::string& get_cache_dir();
// Delete directory and all its contents recursively // Delete directory and all its contents recursively
void remove_all(const std::string& path, bool remove_root = true); bool remove_all(const std::string& path, bool remove_root = true);
// Get size of all files recursively // Get size of all files recursively
u64 get_dir_size(const std::string& path); u64 get_dir_size(const std::string& path);