From f5c7a945c5e6687a86166fb10e0aac846e9bc2f3 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 14 Nov 2023 12:32:48 +0100 Subject: [PATCH] solved apply to bug --- main.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index e77b376..97cc148 100644 --- a/main.py +++ b/main.py @@ -34,18 +34,24 @@ def handle_file_modification(original_file, duplicate_file, modification): print(f"Replaced {duplicate_file} with a symlink to {original_file}") def handle_modification(files, modification, mode, apply_to): - original_file = files[0] # Keep the first file - for duplicate_file in files[1:]: # Iterate over remaining files - if duplicate_file.startswith(tuple(apply_to)): - if mode == 'preview' and modification != 'show': - print(f"Would perform {modification} on {duplicate_file}") - elif mode == 'act': - handle_file_modification(original_file, duplicate_file, modification) - elif mode == 'interactive': - answer = input(f"Do you want to {modification} this file? {duplicate_file} [y/N] ") - if answer.lower() in ['y', 'yes']: + original_file = next((f for f in files if not f.startswith(tuple(apply_to))), files[0]) + for duplicate_file in files: + if duplicate_file != original_file: + if duplicate_file.startswith(tuple(apply_to)): + if mode == 'preview': + print(f"Would perform {modification} on {duplicate_file}") + elif mode == 'act': handle_file_modification(original_file, duplicate_file, modification) - print() + elif mode == 'interactive': + answer = input(f"Do you want to {modification} this file? {duplicate_file} [y/N] ") + if answer.lower() in ['y', 'yes']: + handle_file_modification(original_file, duplicate_file, modification) + else: + print(f"Duplicate file (unmodified): {duplicate_file}") + else: + print(f"Original file kept: {original_file}") + print() + def main(args): directories = args.directories