atomic

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package atomic provides a stage-then-rename WriteFile primitive. Using a sibling temp file + os.Rename collapses what would otherwise be a create-write-close-chmod-rename sequence into a single visible transition, satisfying POSIX atomicity for cache writers that must never expose a partial or zero-byte file to concurrent readers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

func WriteFile(path string, data []byte, perm os.FileMode, syncDir bool) error

WriteFile writes data to path atomically. The file is first written to a sibling temp file in the same directory (ensuring rename stays on the same filesystem / inode device), then renamed into place. Readers always observe either the previous complete contents or the new complete contents.

perm is applied to the staged file before rename; umask still applies via CreateTemp. On any error after staging, the temp file is removed and path is left untouched.

syncDir controls the durability guarantee. When true the function calls Sync on the staged file before rename, then opens and fsyncs the directory after rename — this flushes the rename journal entry so the new name survives a power loss. Set false for high-churn caches whose values are cheap to re-derive on the next reconcile.

Types

This section is empty.

Jump to

Keyboard shortcuts

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