File size: 763 Bytes
9deebf2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """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)
|