filelock

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 5 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 filelock takes exclusive OS locks on files, which the OS drops when the holding process dies. Test processes of every emutest version and the gcpemu CLI share them, so the locking scheme is a contract (ADR 0047).

Index

Constants

This section is empty.

Variables

View Source
var ErrHeld = errors.New("still held")

ErrHeld is a lock that another holder has.

Functions

func Acquire

func Acquire(paths []string, deadline time.Time) (release func(), err error)

Acquire takes an exclusive OS lock on whichever of paths is free first, so that len(paths) holders get in at once. The OS releases it if the process dies. It polls until deadline (zero: forever), then fails with ErrHeld. The caller keeps release reachable until it calls it: a dropped release lets the collector close the file, dropping the lock.

func TryLock

func TryLock(path string, flag int) (release func(), err error)

TryLock takes an exclusive OS lock on path without waiting, opening it with the extra flags (os.O_CREATE to create it). It fails with ErrHeld while another holder has it, and when path was removed or replaced before the lock was taken, since a lock on the old file guards nothing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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