mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 18:54:59 +00:00
fix: Preserve original read-only files across symlinks
This commit is contained in:
parent
e1ab9cc0ab
commit
c3d4fdb4c1
1 changed files with 26 additions and 7 deletions
|
@ -81,8 +81,20 @@ class Commands:
|
||||||
self.help = None
|
self.help = None
|
||||||
self.editor = editor
|
self.editor = editor
|
||||||
|
|
||||||
# Store the original read-only filenames provided via args.read
|
# Store the original read-only filenames provided via args.read.
|
||||||
self.original_read_only_fnames = set(original_read_only_fnames or [])
|
# Keep both the raw path as given and the canonical realpath so we
|
||||||
|
# can match them later even when symlinks (eg /var ↔ /private/var)
|
||||||
|
# are involved.
|
||||||
|
self.original_read_only_fnames = set()
|
||||||
|
for fname in original_read_only_fnames or []:
|
||||||
|
# As provided
|
||||||
|
self.original_read_only_fnames.add(str(fname))
|
||||||
|
# Canonical path (best-effort)
|
||||||
|
try:
|
||||||
|
self.original_read_only_fnames.add(os.path.realpath(fname))
|
||||||
|
except Exception:
|
||||||
|
# Ignore paths that cannot be resolved
|
||||||
|
pass
|
||||||
|
|
||||||
def cmd_model(self, args):
|
def cmd_model(self, args):
|
||||||
"Switch the Main Model to a new LLM"
|
"Switch the Main Model to a new LLM"
|
||||||
|
@ -411,16 +423,23 @@ class Commands:
|
||||||
def _drop_all_files(self):
|
def _drop_all_files(self):
|
||||||
self.coder.abs_fnames = set()
|
self.coder.abs_fnames = set()
|
||||||
|
|
||||||
|
# Helper to compare two paths while ignoring symlinks/resolution.
|
||||||
|
def _paths_match(p1, p2):
|
||||||
|
try:
|
||||||
|
return os.path.samefile(p1, p2)
|
||||||
|
except (FileNotFoundError, OSError):
|
||||||
|
return os.path.normpath(p1) == os.path.normpath(p2)
|
||||||
|
|
||||||
# When dropping all files, keep those that were originally provided via args.read
|
# When dropping all files, keep those that were originally provided via args.read
|
||||||
if self.original_read_only_fnames:
|
if self.original_read_only_fnames:
|
||||||
# Keep only the original read-only files
|
|
||||||
to_keep = set()
|
to_keep = set()
|
||||||
for abs_fname in self.coder.abs_read_only_fnames:
|
for abs_fname in self.coder.abs_read_only_fnames:
|
||||||
rel_fname = self.coder.get_rel_fname(abs_fname)
|
rel_fname = self.coder.get_rel_fname(abs_fname)
|
||||||
if (
|
keep = any(
|
||||||
abs_fname in self.original_read_only_fnames
|
_paths_match(abs_fname, orig) or rel_fname == orig
|
||||||
or rel_fname in self.original_read_only_fnames
|
for orig in self.original_read_only_fnames
|
||||||
):
|
)
|
||||||
|
if keep:
|
||||||
to_keep.add(abs_fname)
|
to_keep.add(abs_fname)
|
||||||
self.coder.abs_read_only_fnames = to_keep
|
self.coder.abs_read_only_fnames = to_keep
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue