"""Filesystem locking helpers for generated output artifacts. Outputs under `output/` are sealed read-only (file 0o444, parent dir 0o555) to prevent accidental in-place mutation. The pipeline briefly relaxes those bits to rewrite, then reseals. """ from pathlib import Path FILE_WRITABLE = 0o644 FILE_SEALED = 0o444 DIR_WRITABLE = 0o755 DIR_SEALED = 0o555 def unlock_for_write(path: Path) -> None: path = Path(path) parent = path.parent if parent.exists(): parent.chmod(DIR_WRITABLE) if path.exists(): path.chmod(FILE_WRITABLE) def seal_output(path: Path) -> None: path = Path(path) if path.exists(): path.chmod(FILE_SEALED) parent = path.parent if parent.exists(): parent.chmod(DIR_SEALED)