fix(dist): stop USER_OWNED_EXCLUDE from filtering nested directories

The copytree ignore lambda in _copy_dist_payload applied USER_OWNED_EXCLUDE
recursively at every directory depth. This caused nested directories whose
names matched exclude entries (bin, logs, cache, etc.) to be silently dropped
during distribution install/update.

Fix: only apply USER_OWNED_EXCLUDE filtering at the root of the staged tree,
matching the two-tier pattern used by _clone_all_copytree_ignore and
_default_export_ignore in profiles.py.

Add 5 tests covering nested bin/logs/cache preservation and top-level
filtering still working.

Fixes #37954
This commit is contained in:
islam666
2026-06-07 21:50:57 -07:00
committed by Teknium
parent 09a5548628
commit e53b74c394
2 changed files with 77 additions and 1 deletions
+6 -1
View File
@@ -573,10 +573,15 @@ def _copy_dist_payload(
if entry.is_dir():
if dest.exists():
shutil.rmtree(dest)
staged_resolved = staged.resolve()
shutil.copytree(
entry,
dest,
ignore=lambda d, names: [n for n in names if n in USER_OWNED_EXCLUDE],
ignore=lambda d, names: (
[n for n in names if n in USER_OWNED_EXCLUDE]
if Path(d).resolve() == staged_resolved
else []
),
)
else:
shutil.copy2(entry, dest)