lock

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package lock wraps gofrs/flock to provide an advisory file lock on .focus/.lock for the duration of a mutating CLI/MCP operation.

Per designs/focus-issue-001.md §"Concurrency", every mutating command acquires this lock to serialize next_id allocation and index.json writes across concurrent invocations. Read-only commands do NOT take the lock — atomic-rename on the writer side guarantees they see a consistent snapshot.

Stale lock files are not a concern: flock is kernel-managed, so a dying process releases its lock when its file descriptor closes. The .lock file itself stays on disk; that's expected and harmless.

Index

Constants

View Source
const FileName = ".lock"

FileName is the lock file's name relative to .focus/.

Variables

This section is empty.

Functions

func With

func With(focusDir string, fn func() error) (err error)

With acquires the .focus/.lock for the duration of fn and releases it on return, regardless of whether fn errors or panics. The preferred API for mutating commands.

Types

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock is a held lock on .focus/.lock. Always Release() what you Acquire(). Use With() if you can; it's harder to forget.

func Acquire

func Acquire(focusDir string) (*Lock, error)

Acquire takes an exclusive lock on .focus/.lock, blocking until the lock is available. Creates the .lock file if it doesn't exist.

func (*Lock) Release

func (l *Lock) Release() error

Release releases the lock and closes the underlying file descriptor. Safe to call multiple times — the second call is a no-op.

Jump to

Keyboard shortcuts

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