1
0
mirror of https://github.com/pirate/ArchiveBox.git synced 2025-08-16 19:44:08 +02:00

skip dir size calculation when path is too long

This commit is contained in:
Nick Sweeting
2024-02-12 21:26:34 -08:00
parent c94ed53570
commit 91c4641199

View File

@@ -146,6 +146,7 @@ def get_dir_size(path: Union[str, Path], recursive: bool=True, pattern: Optional
recursively and limiting to a given filter list
"""
num_bytes, num_dirs, num_files = 0, 0, 0
try:
for entry in os.scandir(path):
if (pattern is not None) and (pattern not in entry.path):
continue
@@ -160,6 +161,9 @@ def get_dir_size(path: Union[str, Path], recursive: bool=True, pattern: Optional
else:
num_bytes += entry.stat(follow_symlinks=False).st_size
num_files += 1
except OSError:
# e.g. FileNameTooLong or other error while trying to read dir
pass
return num_bytes, num_dirs, num_files