Documentation
¶
Overview ¶
Package fsutil holds small filesystem helpers shared across the agent and server. AtomicWriteFile is the durable temp-file → rename pattern that the agent's config writer and both config savers previously each reimplemented (#225), now in one place that also fsyncs the parent directory.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWriteFile ¶
AtomicWriteFile writes data to path atomically and durably. It creates a temp file in the same directory, fsyncs the file, chmods it to perm, renames it over the target, then fsyncs the parent directory so the rename itself survives a crash.
The trailing directory fsync is the crash-safety fix: on Linux/Unix the rename is not durable until the directory entry is flushed, so after power loss the target file could revert to its old content — or, for a first-time write, disappear — even though Write, Sync, and Rename all reported success (#225). The directory sync is best-effort (some filesystems and platforms do not support it) and runs only after the rename has succeeded, so a failure there is logged rather than returned: failing here would be misleading when the new data is already in place.
Types ¶
This section is empty.