mirror of
https://github.com/pirate/ArchiveBox.git
synced 2025-08-17 20:01:44 +02:00
skip dir size calculation when path is too long
This commit is contained in:
@@ -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
|
recursively and limiting to a given filter list
|
||||||
"""
|
"""
|
||||||
num_bytes, num_dirs, num_files = 0, 0, 0
|
num_bytes, num_dirs, num_files = 0, 0, 0
|
||||||
|
try:
|
||||||
for entry in os.scandir(path):
|
for entry in os.scandir(path):
|
||||||
if (pattern is not None) and (pattern not in entry.path):
|
if (pattern is not None) and (pattern not in entry.path):
|
||||||
continue
|
continue
|
||||||
@@ -160,6 +161,9 @@ def get_dir_size(path: Union[str, Path], recursive: bool=True, pattern: Optional
|
|||||||
else:
|
else:
|
||||||
num_bytes += entry.stat(follow_symlinks=False).st_size
|
num_bytes += entry.stat(follow_symlinks=False).st_size
|
||||||
num_files += 1
|
num_files += 1
|
||||||
|
except OSError:
|
||||||
|
# e.g. FileNameTooLong or other error while trying to read dir
|
||||||
|
pass
|
||||||
return num_bytes, num_dirs, num_files
|
return num_bytes, num_dirs, num_files
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user