Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWrite ¶
AtomicWrite writes data to path via a temporary file + rename for crash safety. The perm argument sets the final file permissions (e.g. 0644 for docs, 0755 for hooks).
func AtomicWriteExclusive ¶
AtomicWriteExclusive writes data to path via a temporary file + hard link. Unlike AtomicWrite, it fails if path already exists (returns an error where os.IsExist reports true). This avoids the TOCTOU race inherent in Stat-then-Rename patterns.
func AtomicWriteJSON ¶ added in v1.1.0
AtomicWriteJSON marshals v as indented JSON and writes it to path via writeAtomicDurable. Used for state files where the indented form is worth the handful of extra bytes for human diff-ability. Returns a non-nil error if marshaling fails; the target file is left unchanged in that case.
func AtomicWriteStream ¶ added in v1.1.0
AtomicWriteStream streams src into path via writeAtomicDurable. Used by backup/restore where the source is an already-open file and buffering the full contents into memory would be wasteful.
Types ¶
type FileLock ¶ added in v1.1.0
type FileLock struct {
// contains filtered or unexported fields
}
FileLock holds an exclusive advisory lock on a side-car `.lock` file. Created via NewFileLock and released with Unlock. Not safe for concurrent use by multiple goroutines within a process; the caller should serialize access.
func NewFileLock ¶ added in v1.1.0
NewFileLock creates (or opens) a `<target>.lock` file next to the supplied target path and takes an exclusive advisory lock on it. Callers MUST defer Unlock to release the lock and close the fd.
The lock file is never removed so concurrent processes that race to create it cannot accidentally delete a file another process holds. The lock file contains nothing; only its inode participates in the flock contract.