Documentation
¶
Overview ¶
Package lock provides file-based mutual exclusion for single-instance enforcement.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureDirExists ¶ added in v0.174.0
EnsureDirExists creates the directory containing path with mode 0750 if it does not exist.
Types ¶
type DirLock ¶ added in v0.182.0
type DirLock interface {
// Acquire attempts to acquire the lock, polling every 100ms until
// the lock is acquired, the timeout elapses, or the context is cancelled.
// Returns an error naming the directory and the elapsed timeout on failure.
Acquire(ctx context.Context, timeout time.Duration) error
// Release closes the directory fd, which drops the flock. Idempotent —
// calling on an already-released lock returns nil. No file is removed.
Release(ctx context.Context) error
}
DirLock provides exclusive directory-scoped locking via an advisory flock on the directory fd. It serializes mutations to any file inside a status directory (e.g. prompts/in-progress/) so concurrent processes cannot interleave mid-mutation. The flock is per-fd and kernel-released when the fd is closed, so crash-release is automatic — no sidecar file is ever created on disk.
func NewDirLock ¶ added in v0.182.0
NewDirLock creates a DirLock that acquires an exclusive advisory flock on dirPath itself. dirPath must be a directory that exists at Acquire time; pass filepath.Dir(targetFile) to serialize mutations of files in that directory.