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 ¶
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 ¶
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 ¶
AcquireNamed is Acquire on Path(name), bounded by timeout as well as ctx.