Skip to content

Commit

Permalink
fix: Prevent exception during existence check
Browse files Browse the repository at this point in the history
- Add "safe" existence check to files which catches OSErrors that may
  occur when trying to stat files
- Use "safe" existence check during final existence check
  • Loading branch information
arsenetar committed Jan 12, 2023
1 parent 81daddd commit 057be02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ def can_handle(cls, path):
"""Returns whether this file wrapper class can handle ``path``."""
return not path.is_symlink() and path.is_file()

def exists(self) -> bool:
"""Safely check if the underlying file exists, treat error as non-existent"""
try:
return self.path.exists()
except OSError as ex:
logging.warning(f"Checking {self.path} raised: {ex}")
return False

def rename(self, newname):
if newname == self.name:
return
Expand Down
2 changes: 1 addition & 1 deletion core/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get_dupe_groups(self, files, ignore_list=None, j=job.nulljob):
if not self.mix_file_kind:
matches = [m for m in matches if get_file_ext(m.first.name) == get_file_ext(m.second.name)]
if self.include_exists_check:
matches = [m for m in matches if m.first.path.exists() and m.second.path.exists()]
matches = [m for m in matches if m.first.exists() and m.second.exists()]
matches = [m for m in matches if not (m.first.is_ref and m.second.is_ref)]
if ignore_list:
matches = [m for m in matches if not ignore_list.are_ignored(str(m.first.path), str(m.second.path))]
Expand Down

0 comments on commit 057be02

Please sign in to comment.