Documentation
¶
Overview ¶
Package fsutil holds mache's file-publishing primitives: how a file gets from "being written" to "visible at its path" without a reader ever seeing the part in between.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyFile ¶
CopyFile copies src to dst, creating or truncating dst. It is NOT atomic; wrap it in Publish when a reader may be looking at dst.
func Publish ¶
Publish produces a file at a private path and moves it to final in one rename, so a reader of final sees the previous file or the finished one — never a truncated, half-written, or missing one.
produce is handed a path that does not exist yet unless seed is set, in which case it starts as a copy of seed (an incremental update copies the current final and edits the copy). It may open, write and close the path however it likes; SQLite writers included.
The work happens in a private directory beside final, for two reasons. A rename is only atomic within one filesystem, and TMPDIR is often another. And a directory of its own makes the publish check structural: when produce returns, that directory must hold exactly the one file. Anything else there — an uncheckpointed `-wal`, a hot `-journal` — is state the file depends on, and renaming the file without it would publish a database missing committed writes. That is refused, not guessed at.
A reader that already has final open keeps reading the file it opened: the rename replaces the name, not the inode. Seeing the new file means reopening.
When final is a symlink, its target is replaced and the link is left alone, as an in-place write through the link would have done.
func WriteFileAtomic ¶
WriteFileAtomic writes data to path through Publish. The file is created 0o600, as the os.CreateTemp-based version this replaced did.
Types ¶
This section is empty.