fs: Make fs::get_dir_size able to report an error

This commit is contained in:
Eladash 2020-02-22 17:04:35 +02:00 committed by Ani
parent 569e1c2df6
commit 0d4f8ca234
3 changed files with 67 additions and 18 deletions

View file

@ -1639,7 +1639,14 @@ u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment)
{
u64 result = 0;
for (const auto& entry : dir(path))
const auto root_dir = dir(path);
if (!root_dir)
{
return static_cast<u64>(umax);
}
for (const auto& entry : root_dir)
{
if (entry.name == "." || entry.name == "..")
{
@ -1653,7 +1660,14 @@ u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment)
if (entry.is_directory == true)
{
result += get_dir_size(path_append(path, entry.name), rounding_alignment);
const u64 size = get_dir_size(path_append(path, entry.name), rounding_alignment);
if (size == umax)
{
return size;
}
result += size;
}
}