fix: _paths_overlap() false positives for sibling paths

The old implementation compared a common-length prefix of path parts,
which incorrectly reported overlaps for sibling paths sharing a directory
(e.g. /a/b/c and /a/b/d both report True).

The fix only returns True when one path is a proper prefix of the other
by comparing the shorter path's parts against the same-length prefix
of the longer path.
This commit is contained in:
vominh1919 2026-04-21 10:42:58 +07:00
parent 78fa758451
commit 399dc3aa74

View file

@ -332,8 +332,9 @@ def _paths_overlap(left: Path, right: Path) -> bool:
if not left_parts or not right_parts:
# Empty paths shouldn't reach here (guarded upstream), but be safe.
return bool(left_parts) == bool(right_parts) and bool(left_parts)
common_len = min(len(left_parts), len(right_parts))
return left_parts[:common_len] == right_parts[:common_len]
if len(left_parts) < len(right_parts):
return left_parts == right_parts[:len(left_parts)]
return right_parts == left_parts[:len(right_parts)]