fsutil

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

func CopyFile(src, dst string) error

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

func Publish(final, seed string, produce func(path string) error) error

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

func WriteFileAtomic(path string, data []byte) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL