Documentation
¶
Overview ¶
Package xdgcache provides shared filesystem primitives for user data and caches: same-directory temp-and-rename replacement, non-blocking process locks, and XDG-aware cache-directory resolution.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLocked = errors.New("xdgcache: lock held by another process")
ErrLocked is returned by OpenLock when the lock file is held by another process. Callers that want to queue rather than fail-fast can implement their own retry loop; this package does not.
Functions ¶
func CacheDir ¶
CacheDir returns the daemon's on-disk cache root for sub, resolving $XDG_CACHE_HOME first and falling back to $HOME/.cache when XDG isn't set (the XDG spec's documented default). sub is the per-feature subdirectory ("spx-members", "update", "gamma-zero" etc.) — kept as a required argument so call sites read self-documentingly and the shared root is never returned by accident.
Returns an error only when both XDG_CACHE_HOME and HOME are unset, which on a real OS user account doesn't happen. Tests should pass t.TempDir() directly to whichever helper needs a cache path rather than relying on this function.
func WriteAtomic ¶
WriteAtomic replaces path with data by renaming a temporary file created in the same directory. Readers therefore observe either the old or new name on supported local filesystems. The parent directory is created with mode 0755; the resulting inode retains the temporary file's mode, normally 0600. WriteAtomic does not fsync the file or directory and therefore does not claim power-loss durability.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a held flock. Released by calling Release; safe to call multiple times. The underlying file descriptor stays open for the lock's lifetime — closing the file releases the flock as a side effect, but Release does so explicitly to surface unlock errors.
func OpenLock ¶
OpenLock takes a non-blocking exclusive flock on path. The parent directory is created if missing. Returns ErrLocked if the lock is already held by another process (LOCK_NB EWOULDBLOCK), or a wrapped error for any other failure mode.
The lock file is never deleted by this package — the inode is the lock identity, so unlinking it under contention would let a second caller create a fresh file at the same path and acquire it independently. Callers wanting cleanup should remove the file at a known-quiescent point.