add check for existing path
This commit is contained in:
parent
226d5e9bb2
commit
b6f9479bf7
1 changed files with 30 additions and 27 deletions
|
@ -103,33 +103,36 @@ class find_duplicate_files:
|
|||
def recursive_scandir(self, path, ignore_hidden_files=True):
|
||||
''' Recursively scan a directory for files'''
|
||||
files = dict()
|
||||
try:
|
||||
for file in os.scandir(path):
|
||||
if self.limit > 0 and len(files) > self.limit:
|
||||
self._log.debug(f"# Limit of {self.limit} passed ({len(files)})")
|
||||
break
|
||||
if not file.name.startswith('.'):
|
||||
if not self._test_exclude(file.path):
|
||||
if file.is_file():
|
||||
check_cache = self._check_file_cache(file.path)
|
||||
if check_cache:
|
||||
files[check_cache] = file.path
|
||||
else:
|
||||
with open(file.path, 'rb') as file_pointer:
|
||||
file_content = file_pointer.read()
|
||||
hash = zlib.adler32(file_content)
|
||||
files[hash] = file.path
|
||||
self._cache_file(file.path, hash)
|
||||
elif file.is_dir(follow_symlinks=False):
|
||||
more_files = self.recursive_scandir(
|
||||
file.path,
|
||||
ignore_hidden_files=ignore_hidden_files
|
||||
)
|
||||
if more_files:
|
||||
files = { **files, **more_files }
|
||||
except PermissionError as error:
|
||||
self._log.warning(f"# Permission denied accessing folder '{path}'")
|
||||
self._log.debug(f"# Found {len(files)} files in '{path}'. Cache contains {self._cache_size()} records.")
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
for file in os.scandir(path):
|
||||
if self.limit > 0 and len(files) > self.limit:
|
||||
self._log.debug(f"# Limit of {self.limit} passed ({len(files)})")
|
||||
break
|
||||
if not file.name.startswith('.'):
|
||||
if not self._test_exclude(file.path):
|
||||
if file.is_file():
|
||||
check_cache = self._check_file_cache(file.path)
|
||||
if check_cache:
|
||||
files[check_cache] = file.path
|
||||
else:
|
||||
with open(file.path, 'rb') as file_pointer:
|
||||
file_content = file_pointer.read()
|
||||
hash = zlib.adler32(file_content)
|
||||
files[hash] = file.path
|
||||
self._cache_file(file.path, hash)
|
||||
elif file.is_dir(follow_symlinks=False):
|
||||
more_files = self.recursive_scandir(
|
||||
file.path,
|
||||
ignore_hidden_files=ignore_hidden_files
|
||||
)
|
||||
if more_files:
|
||||
files = { **files, **more_files }
|
||||
except PermissionError as error:
|
||||
self._log.warning(f"# Permission denied accessing folder '{path}'")
|
||||
self._log.debug(f"# Found {len(files)} files in '{path}'. Cache contains {self._cache_size()} records.")
|
||||
else:
|
||||
self._log.warning(f"# Folder '{path}' doesn't exist")
|
||||
return files
|
||||
|
||||
def _init_log(self):
|
||||
|
|
Loading…
Reference in a new issue