Allow to cancel dir size calculation (#13134)

This commit is contained in:
Elad Ashkenazi 2022-12-30 10:34:35 +02:00 committed by GitHub
parent eeda958f33
commit 382a27cb2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 4 deletions

View file

@ -1924,7 +1924,7 @@ bool fs::remove_all(const std::string& path, bool remove_root, bool is_no_dir_ok
return true;
}
u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment)
u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment, atomic_t<bool>* cancel_flag)
{
u64 result = 0;
@ -1937,6 +1937,11 @@ u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment)
for (const auto& entry : root_dir)
{
if (cancel_flag && *cancel_flag)
{
return umax;
}
if (entry.name == "." || entry.name == "..")
{
continue;

View file

@ -669,7 +669,7 @@ namespace fs
bool remove_all(const std::string& path, bool remove_root = true, bool is_no_dir_ok = false);
// Get size of all files recursively
u64 get_dir_size(const std::string& path, u64 rounding_alignment = 1);
u64 get_dir_size(const std::string& path, u64 rounding_alignment = 1, atomic_t<bool>* cancel_flag = nullptr);
enum class error : uint
{