From ce5db7c6da4c3095f777b180a7b708e819315a6e Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 14 Nov 2023 12:41:52 +0100 Subject: [PATCH] Solved symlink bug --- main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 97cc148..56026a5 100644 --- a/main.py +++ b/main.py @@ -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}")