Documentation
¶
Overview ¶
Package buildlock provides an exclusive, crash-safe lock on a build output directory so two sarde processes cannot write into the same dist/ at once (a second dev server or a build racing a dev server silently corrupts fingerprinted assets; see my-docs/handoffs/dev-server-asset-404-handoff.md).
The lock is a kernel advisory lock held on <outputDir>/.sarde.lock for the lifetime of the owning session. The file also carries one line of JSON metadata (pid, command, version, start time) used purely for diagnostics: the OS lock is authoritative, so a crash releases the lock automatically and leftover lock files never require manual cleanup.
Limitations: sarde binaries built before this package never acquire the lock, so it cannot defend against them. Network filesystems (SMB, NFS) have unreliable locking semantics; keep the output dir on local disk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ErrLocked ¶
ErrLocked is returned by Acquire when another process holds the lock on the output directory. Meta is the zero value when MetaErr is non-nil.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a held reference to an output directory's exclusive lock.
func Acquire ¶
Acquire creates outputDir if needed and takes an exclusive, non-blocking, crash-safe lock on it. cmd is a short diagnostic label ("dev", "build", "sidecar-preview", "sidecar-build") embedded in the lock file's metadata. Re-entrant within the same process: repeated calls for the same output directory succeed and reference-count instead of re-locking.
func (*Lock) Release ¶
Release drops this reference. The OS lock is released and the file closed only when the last in-process reference for the output directory is gone. The lock FILE is deliberately left in place: deleting it on release would let a contender holding a handle to the removed inode and a newcomer creating a fresh file both "acquire" the same directory. Idempotent and nil-safe.