1
0
espelhamento de https://github.com/arsenetar/dupeguru.git sincronizado 2025-09-11 17:58:17 +00:00

fix: Prevent exception during existence check

- 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
Esse commit está contido em:
Andrew Senetar 2023-01-11 23:07:06 -06:00
commit 057be0294a
Assinado por: arsenetar
ID da chave GPG: C63300DCE48AB2F1
2 arquivos alterados com 9 adições e 1 exclusões

Ver arquivo

@ -315,6 +315,14 @@ class File:
"""Returns whether this file wrapper class can handle ``path``.""" """Returns whether this file wrapper class can handle ``path``."""
return not path.is_symlink() and path.is_file() 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): def rename(self, newname):
if newname == self.name: if newname == self.name:
return return

Ver arquivo

@ -172,7 +172,7 @@ class Scanner:
if not self.mix_file_kind: 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)] matches = [m for m in matches if get_file_ext(m.first.name) == get_file_ext(m.second.name)]
if self.include_exists_check: 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)] matches = [m for m in matches if not (m.first.is_ref and m.second.is_ref)]
if ignore_list: if ignore_list:
matches = [m for m in matches if not ignore_list.are_ignored(str(m.first.path), str(m.second.path))] matches = [m for m in matches if not ignore_list.are_ignored(str(m.first.path), str(m.second.path))]