INNER CODE UNIT · Python
copy_tree_without_symlinks
i3T4AN/KADATH · kadath/engine.py:126
def copy_tree_without_symlinks(source: Path, destination: Path) -> None:
destination.mkdir(parents=True, exist_ok=True)
for item in sorted(source.rglob("*")):
try: mode = item.lstat().st_mode
except OSError: continue
if stat.S_ISLNK(mode): continue
target = destination / item.relative_to(source)
if stat.S_ISDIR(mode): target.mkdir(parents=True, exist_ok=True)
elif stat.S_ISREG(mode):
target.parent.mkdir(parents=True, exist_ok=True); shutil.copy2(item, target, follow_symlinks=False)
def make_tree_owner_writable(root: Path) -> None:
"""Undo kernel evidence sealing before a scoped deletion or replacement."""
if not root.exists(): return
for directory, names, files in os.walk(root, topdown=False):
for name in files:
try: (Path(directory) / name).chmod(0o600)