clonelock

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clonelock keeps one clone-changing job at a time on each clone: a worktree made or removed, a release, a hooks install, a checks run, a script, or a pull. A tool updating itself, or being installed, holds its folder the same way. A job that finds its clone busy learns what holds it, which the window shows: "A release is using acme-org/sdk right now."

A clone is keyed by paths.Resolved, so a path through a symbolic link shares the lock of the folder it names. The locks are in-process: they keep the app's own jobs apart, not another program's.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("the clone is busy")

ErrBusy is matched by every *BusyError.

Functions

This section is empty.

Types

type BusyError

type BusyError struct {
	Holder Holder
}

BusyError is returned for a clone another job holds, naming it. Its text is the holder's Sentence.

func (*BusyError) Error

func (e *BusyError) Error() string

Error returns the holder's Sentence.

func (*BusyError) Is

func (e *BusyError) Is(target error) bool

Is reports ErrBusy.

type Holder

type Holder struct {
	Kind Kind

	// Repo is what the window calls the clone: its repository on GitHub, as in
	// "acme-org/sdk", or else its folder. Empty, the sentence says "this clone".
	Repo string

	// Title is the run's title, and RunID the run, for the window to offer; a worktree
	// change has neither.
	Title string
	RunID int64
}

Holder says what holds a clone, for the user.

func (Holder) Sentence

func (h Holder) Sentence() string

Sentence says what the holder is doing, for the user: "A release is using acme-org/sdk right now."

type Kind

type Kind string

Kind is the kind of job that holds a clone.

const (
	KindRelease  Kind = "release"
	KindHooks    Kind = "hooks"
	KindChecks   Kind = "checks"
	KindScript   Kind = "script"
	KindWorktree Kind = "worktree"

	// KindPull is a clone's branch pulled from origin, fast-forward only.
	KindPull Kind = "gitPull"

	// KindUpdate is a tool updating itself, which holds the folder its copy is in, and
	// KindInstall the app installing a tool, which holds the folder it places it in.
	KindUpdate  Kind = "update"
	KindInstall Kind = "install"

	// KindOrphan is a run from before the app restarted, still running, which the app
	// follows under a placeholder lock.
	KindOrphan Kind = "orphan"
)

The kinds of job that hold a clone.

type Set

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

Set holds a lock per clone. The zero Set is ready to use, and it is safe for concurrent use. One Set serves the whole app, so every job that changes a clone sees every other.

func New

func New() *Set

New returns an empty Set.

func (*Set) Holder

func (s *Set) Holder(path string) (Holder, bool)

Holder returns the job that holds path's clone, and true, or false when it is free.

func (*Set) Lock

func (s *Set) Lock(ctx context.Context, path string, h Holder) (release func(), err error)

Lock takes path's clone for h, waiting while another job holds it, until ctx ends.

func (*Set) LockWaitingFor

func (s *Set) LockWaitingFor(ctx context.Context, path string, h Holder, waitFor func(held Holder) bool,
) (release func(), err error)

LockWaitingFor takes path's clone for h. While a job that waitFor accepts holds it, it waits, until ctx ends; a job waitFor refuses fails it at once with a *BusyError naming that job. It fails at once, too, when ctx has already ended. A ctx that ends fails it with ctx.Err() itself, as a semaphore does, so callers word it as they word any other.

func (*Set) TryLock

func (s *Set) TryLock(path string, h Holder) (release func(), held Holder, ok bool)

TryLock takes path's clone for h when it is free, and returns the release, which may be called more than once. When another job holds the clone, it returns that job's Holder and false, without waiting.

Jump to

Keyboard shortcuts

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