Solved symlink bug

This commit is contained in:
Kevin Veen-Birkenbach 2023-11-14 12:41:52 +01:00
parent f5c7a945c5
commit ce5db7c6da
1 changed files with 5 additions and 3 deletions

View File

@ -13,13 +13,15 @@ def md5sum(filename):
def find_duplicates(directories):
hashes = defaultdict(list)
for directory in directories:
for root, dirs, files in os.walk(directory):
for root, dirs, files in os.walk(directory, followlinks=False):
for filename in files:
path = os.path.join(root, filename)
file_hash = md5sum(path)
hashes[file_hash].append(path)
if not os.path.islink(path):
file_hash = md5sum(path)
hashes[file_hash].append(path)
return {file_hash: paths for file_hash, paths in hashes.items() if len(paths) > 1}
def handle_file_modification(original_file, duplicate_file, modification):
if modification == 'delete':
print(f"Deleting {duplicate_file}")