fslock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 4 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 fslock takes an exclusive, non-blocking operating-system lock on a file. The lock, not the file's existence, is the guard: the OS drops it when the holder exits however it exits, so a crashed process leaves no stale lock, and the file is never deleted (deleting a lock file races a process about to open it).

POSIX uses flock(2), which conflicts per open file description; Windows uses LockFileEx, which conflicts per handle. Either way two Acquire calls in one process conflict, which is what a CLI checking for a running server needs. Locks on network filesystems are only as reliable as the filesystem's lock emulation.

Index

Constants

This section is empty.

Variables

View Source
var ErrHeld = errors.New("fslock: lock is held")

ErrHeld means another process (or another Acquire in this one) holds the lock.

Functions

This section is empty.

Types

type Lock

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

Lock is a held lock. Release it exactly once.

func Acquire

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

Acquire creates path if absent (owner-only) and locks it exclusively, failing at once with ErrHeld when it is already locked. The caller must keep the returned *Lock reachable until Release: an unreachable Lock's file is closed by its finalizer, which unlocks it.

func (*Lock) Release

func (l *Lock) Release() error

Release unlocks and closes the file. The file stays on disk.

Jump to

Keyboard shortcuts

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