Skip to main content

Module lockfile

Module lockfile 

Source
Expand description

Session lockfile — explicit “this worktree is in use” marker.

Written when a user enters a worktree via gw shell or gw start. Removed on Drop. Readers verify PID liveness and delete stale files.

Structs§

LockEntry
Serialized lockfile contents describing the session that owns a worktree.
SessionLock
RAII guard that removes the lockfile when dropped, provided the lockfile still belongs to this process. A Drop that blindly removed the file would delete another session’s lock if two processes raced the acquire.

Enums§

AcquireError
Outcome of an acquire call. Callers may want to distinguish “an active session already owns this worktree” (should block entry) from “we could not write the lockfile at all” (degrade to a warning and proceed).

Constants§

LOCK_VERSION
Current on-disk lockfile schema version. A mismatching version makes the lockfile “foreign” for the reader — read_and_clean_stale returns it as-is without removing the file. Writers still check PID ownership, so a foreign-version entry held by another PID is treated as a live foreign lock by acquire and refused.

Functions§

acquire
Acquire an exclusive session lock for the given worktree. Cleans up stale locks; returns AcquireError::ForeignLock if a live foreign PID holds the lock, or AcquireError::Io/AcquireError::Serde for I/O / serialization failures.
pid_alive
Check whether a process with the given PID is currently alive.
read_and_clean_stale
Read the current lock entry, cleaning up if the owner is gone.