lock

package
v0.182.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: BSD-2-Clause Imports: 10 Imported by: 0

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

func EnsureDirExists(ctx context.Context, path string) error

EnsureDirExists creates the directory containing path with mode 0750 if it does not exist.

func FilePath added in v0.17.21

func FilePath(dir string) string

FilePath returns the lock file path for a given directory.

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

func NewDirLock(dirPath string) DirLock

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.

type Locker

type Locker interface {
	Acquire(ctx context.Context) error
	Release(ctx context.Context) error
}

Locker provides exclusive access control to prevent concurrent dark-factory instances.

func NewLocker

func NewLocker(dir string) Locker

NewLocker creates a new Locker for the specified directory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL