Skip to content

Commit

Permalink
Merge pull request #7474 from kozlovsky/fix/path_size
Browse files Browse the repository at this point in the history
Fixes #7473 FileNotFoundError when displaying the settings page
  • Loading branch information
kozlovsky authored Jun 12, 2023
2 parents c80f825 + 42e4a03 commit ad0354f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tribler/core/utilities/path_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ def size(self, include_dir_sizes: bool = True) -> int:
for root, dir_names, file_names in os.walk(self):
names = itertools.chain(dir_names, file_names) if include_dir_sizes else file_names
paths = (os.path.join(root, name) for name in names)
size += sum(os.path.getsize(p) for p in paths if os.path.exists(p))
for p in paths:
try:
size += os.path.getsize(p)
except OSError:
# It can be FileNotFoundError or PermissionError. We can't use the `os.path.exists` check
# because, in case of a race condition, a file (such as `sqlite/knowledge.db-journal`)
# can be deleted right after the `exists` check.
pass
return size

def startswith(self, text: str) -> bool:
Expand Down

0 comments on commit ad0354f

Please sign in to comment.