lock

package
v0.176.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 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 FileLockPath added in v0.174.0

func FileLockPath(targetPath string) string

FileLockPath returns the lock file path for a given target file path.

func FilePath added in v0.17.21

func FilePath(dir string) string

FilePath returns the lock file path for a given directory.

Types

type FileLock added in v0.174.0

type FileLock 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 path and the elapsed timeout on failure.
	Acquire(ctx context.Context, timeout time.Duration) error
	// Release unlocks and removes the lock file. Idempotent — calling on an
	// already-released lock returns nil.
	Release(ctx context.Context) error
}

FileLock provides exclusive file-based locking with a per-path lock file. Unlike Locker (which locks a project-wide .dark-factory.lock), FileLock is used to serialize mutations to individual files so that concurrent processes (e.g. a daemon and the doctor command) cannot corrupt mid-write.

func NewFileLock added in v0.174.0

func NewFileLock(path string) FileLock

NewFileLock creates a FileLock for the given target path. The lock file is <path>.lock in the same directory as path.

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