filelock

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 4 Imported by: 1 module, 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 filelock takes an advisory lock the kernel drops when this process exits, however it exits. A lock named only by the file's own contents would need an age rule to survive a killed process, and no age works: shorter than the slowest holder and it evicts a live one, longer and a killed one strands the next run.

Locks require a local filesystem; NFS home directories are not supported.

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("the lock is already held")

ErrLocked reports that another holder has the lock, as opposed to a lock file that could not be opened at all. The holder need not be another process: a second Acquire in this one is refused the same way.

Functions

This section is empty.

Types

type Lock

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

Lock is one held lock; Release gives it up.

func Acquire

func Acquire(path string, perm os.FileMode) (*Lock, error)

Acquire creates the directory and the lock file as needed and takes a non-blocking exclusive lock on it. perm applies only to a file this call creates.

func (*Lock) Release

func (l *Lock) Release() error

Release drops the lock and leaves the file behind. Unlinking it would let a process that opened it before the unlink and one that creates it after hold locks on two different files at one path, which is the race the lock exists to prevent.

Jump to

Keyboard shortcuts

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