filelock

package
v0.56.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 8 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 is a cross-process advisory lock on a file: flock(2) on unix, LockFileEx on Windows. The OS drops the lock when the holder exits or is killed, so a crashed process never leaves it stuck. Acquire waits, but only as long as its context allows: a hung holder costs a bounded wait and a clear error, never a frozen memcode.

It exists for credential refresh: OAuth refresh tokens are single-use and rotate, so the read→refresh→write-back of a login must not interleave across processes (two memcode sessions, or memcode and the vendor's own CLI when it honors the same convention).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Path

func Path(name string) string

Path is the lock file for a named resource under the memcode state home (statedir.Home()/locks/<name>.lock) — never inside another tool's directory.

Types

type Lock

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

Lock is a held lock. Release it exactly once (extra calls are no-ops).

func Acquire

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

Acquire takes an exclusive lock on path, creating the file (and its directory) when missing. It blocks until the lock is free or ctx is done; a ctx expiry returns an error wrapping ctx.Err().

func AcquireNamed

func AcquireNamed(ctx context.Context, name string, timeout time.Duration) (*Lock, error)

AcquireNamed is Acquire on Path(name), bounded by timeout as well as ctx.

func (*Lock) Release

func (l *Lock) Release() error

Release drops the lock. Closing the descriptor releases it too, which is also what the OS does when the process dies.

Jump to

Keyboard shortcuts

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