Files
agent-zero/plugins/_time_travel/helpers/locking.py
Alessandro 78d3f8d27d Protect Time Travel capture, restores, and cleanup
Treat Git paths literally so unusual filenames cannot expand into excluded files. Reject restores that would change excluded paths, nested Git workspaces, or files through directory symlinks.

Serialize complete workspace operations with reentrant cross-process locks shared by retention. Skip busy or symlinked histories, fail closed when owners cannot be enumerated, and count only successful cleanup.

Verified with 38 focused tests, including cross-process cleanup, concurrent snapshots, exclusion bypasses, and restore safety. Keep test shadow repositories isolated from user history.
2026-11-12 15:35:38 +01:00

12 lines
386 B
Python

"""Locks shared by history operations and retention, outside removable repositories."""
from pathlib import Path
from filelock import FileLock
def workspace_lock(shadow_path: Path) -> FileLock:
lock_dir = shadow_path.parent / ".locks"
lock_dir.mkdir(parents=True, exist_ok=True)
return FileLock(str(lock_dir / f"{shadow_path.name}.lock"), timeout=20, is_singleton=True)