instancelock

package
v0.0.0-...-b046e25 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package instancelock lets one process at a time own a resource, such as the Caddyfile that caddy-view edits.

The lock is an exclusive SQLite transaction on a small file, held on one connection for as long as the lock is held. SQLite takes the operating system's file locks for it, and the system drops them when the process ends, however it ends, so there is no stale lock to clear, no PID file and no timeout. It reuses the SQLite driver the history store already needs and works the same on Linux, macOS and Windows. It holds between processes on one machine that see the file through the same local file system; it is not meant for network file systems.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("the lock is held by another process")

ErrBusy means another holder, in this process or in another, has the lock.

Functions

This section is empty.

Types

type Lock

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

Lock is a held lock. The zero value holds nothing.

func Acquire

func Acquire(ctx context.Context, path string) (*Lock, error)

Acquire takes the lock kept in the file at path, creating the file if needed, without waiting. It fails with ErrBusy when somebody else holds it, and with another error when the file cannot be used: its directory is missing or not writable, or the path is a symbolic link. The lock is released by Release, or by the system when the process ends.

func (*Lock) Release

func (l *Lock) Release() error

Release gives the lock up. It is safe to call more than once.

Jump to

Keyboard shortcuts

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