GotPsi / src /core /output_lock.py
ebrinz's picture
Flatten history: re-sanitized (128-bit hash) GotPsi public dataset
9deebf2
Raw
History Blame Contribute Delete
763 Bytes
"""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)