Skip to main content

Module lock_cli

Module lock_cli 

Source
Expand description

Envelope-aware wrapper around the socket_patch_core::patch::apply_lock advisory lock.

Mutating subcommands (apply, rollback, repair, remove) all need the same shape: acquire the lock at the top of run, on contention emit a JSON envelope with errorCode: "lock_held" (or stderr in human mode) and exit 1. This module centralises that emission so the four call sites stay one line each.

The lock itself is in socket-patch-core (cross-crate, also used by tests). This module is the CLI-side glue that knows how to render the failure through the shared crate::json_envelope.

Structs§

LockAcquired
Outcome of a successful lock acquisition. Callers attach a lock_broken event to their own envelope when broke_lock is true, so the audit trail follows the same conventions as the rest of the command’s output.

Constants§

LOCK_BROKEN_CODE
Stable errorCode tag emitted as a Skipped warning event when --break-lock actually deletes a pre-existing lock file. Exposed for downstream consumers and integration tests that pattern-match on it.

Functions§

acquire_or_emit
Try to acquire <socket_dir>/apply.lock and return the guard, or emit a failure envelope and a non-zero exit code.
lock_broken_event
Build the warning event that callers attach to their envelope when LockAcquired::broke_lock is true. Artifact-level (no PURL) since the action targets the .socket/ directory itself, not a specific package.
record_lock_broken
Convenience: record the lock_broken warning event on an envelope. Mirrors the inline pattern at each call site so we don’t drift on the action / errorCode pair.