repolock

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package repolock serializes mutating aiwf invocations on the same repository. The lock is held for the duration of a single verb (read tree → validate → write → commit) so concurrent allocators can't pick the same id.

Implementation: a POSIX advisory file lock (flock(2)) on <root>/.git/aiwf.lock. The lockfile is created on first Acquire and never removed — the lock lives on the open file descriptor, not on the file's existence. Crashed processes release the lock via the kernel's fd cleanup, so stale lockfiles never block a future invocation.

Read-only verbs (check, history, status, render, doctor) do not acquire the lock — they can safely run concurrently with each other and with mutations (the worst they see is a snapshot from before the mutation lands).

Windows: a separate stub in repolock_windows.go satisfies the type contract so the rest of the binary cross-compiles, but every Acquire returns an error. The cmd/aiwf entry point's assertSupportedOS check refuses to run on Windows up front, so users see one clear message instead of a deep stack failure.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("another aiwf process is running on this repo")

ErrBusy is returned by Acquire when another process holds the lock and the timeout elapsed without it being released.

Functions

This section is empty.

Types

type Lock

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

Lock is a held repolock. Callers must Release it (typically via defer) before the process exits, although the kernel will release it automatically on exit if Release is missed.

func Acquire

func Acquire(root string, timeout time.Duration) (*Lock, error)

Acquire takes an exclusive lock on root's aiwf lockfile. If another process holds the lock, Acquire polls until the lock is released or timeout elapses. A zero timeout returns ErrBusy immediately if the lock is held; otherwise the lock is taken and returned.

The lockfile lives at <root>/.git/aiwf.lock when .git/ exists (the default for any aiwf-managed repo); otherwise at <root>/.aiwf.lock as a fallback for tests and for tooling integration before `git init`.

func (*Lock) Release

func (l *Lock) Release() error

Release frees the lock. Idempotent: a second Release is a no-op.

Jump to

Keyboard shortcuts

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