From e2ebde75bee41f8bb721bb2da7c856aafd8f2d2f Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sat, 30 Nov 2024 13:12:31 -0800 Subject: [PATCH] fix: improve /drop handling of relative paths with samefile check --- aider/commands.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 08c5f3ea2..de865802e 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -808,8 +808,21 @@ class Commands: # Expand tilde in the path expanded_word = os.path.expanduser(word) - # Handle read-only files with substring matching - read_only_matched = [f for f in self.coder.abs_read_only_fnames if expanded_word in f] + # Handle read-only files with substring matching and samefile check + read_only_matched = [] + for f in self.coder.abs_read_only_fnames: + if expanded_word in f: + read_only_matched.append(f) + continue + + # Try samefile comparison for relative paths + try: + abs_word = os.path.abspath(expanded_word) + if os.path.samefile(abs_word, f): + read_only_matched.append(f) + except (FileNotFoundError, OSError): + continue + for matched_file in read_only_matched: self.coder.abs_read_only_fnames.remove(matched_file) self.io.tool_output(f"Removed read-only file {matched_file} from the chat")