Create path if needed and verify it is writable, or exit with an error.
Source code in src/terok_sandbox/_util/_fs.py
| def ensure_dir_writable(path: Path, label: str) -> None:
"""Create *path* if needed and verify it is writable, or exit with an error."""
try:
path.mkdir(parents=True, exist_ok=True)
except Exception as e:
raise SystemExit(f"{label} directory is not writable: {path} ({e})")
if not path.is_dir():
raise SystemExit(f"{label} path is not a directory: {path}")
if not os.access(path, os.W_OK | os.X_OK):
uid = os.getuid()
gid = os.getgid()
raise SystemExit(
f"{label} directory is not writable: {path}\n"
f"Fix permissions for the user running terok-sandbox (uid={uid}, gid={gid}). "
f"Example: sudo chown -R {uid}:{gid} {path}"
)
|