fix(config): ensure symlink mappings are recorded before duplicate check

Update symlink traversal logic to always record path mappings before checking for visited directories. This prevents valid link->target pairs from being dropped when the target directory has already been visited via another path. Also correct path mapping lookup to properly replace link paths with their actual target paths.
This commit is contained in:
Will Miao
2025-12-09 21:46:33 +08:00
parent 40f7f14c1b
commit 6b3a11e01a

View File

@@ -396,10 +396,13 @@ class Config:
continue
normalized_target = self._normalize_path(target_path)
# Always record the mapping even if we already visited
# the real directory via another path. This prevents the
# traversal order from dropping valid link->target pairs.
self.add_path_mapping(entry_path, target_path)
if normalized_target in visited_dirs:
continue
visited_dirs.add(normalized_target)
self.add_path_mapping(entry_path, target_path)
stack.append(target_path)
continue
@@ -504,9 +507,9 @@ class Config:
normalized_link = os.path.normpath(link_path).replace(os.sep, '/')
# Check if the path is contained in any mapped target path
for target_path, link_path in self._path_mappings.items():
if normalized_link.startswith(target_path):
# If the path starts with the target path, replace with actual path
mapped_path = normalized_link.replace(target_path, link_path, 1)
if normalized_link.startswith(link_path):
# If the path starts with the link path, replace with actual path
mapped_path = normalized_link.replace(link_path, target_path, 1)
return mapped_path
return link_path