fsatomic

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package fsatomic provides crash-safe single-file persistence: data is written to a temp file in the target directory, synced to disk, and then atomically moved over the target. On Windows, where rename-over-existing is not atomic, the existing file is shuffled to a .bak first and restored on failure; readers that care about mid-replace crashes can fall back to that .bak.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

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

WriteFile atomically replaces path with data. The temp file is created in path's directory so the final rename never crosses filesystems. On POSIX, both the file and the parent directory are synced so the renamed directory entry is durable after return. Replacement files keep os.CreateTemp's private permissions; perm is accepted for parity with os.WriteFile but is never used to widen access beyond the process umask.

func WriteJSON

func WriteJSON(path string, v any) error

WriteJSON marshals v as two-space-indented JSON and atomically writes it to path via WriteFile (temp + fsync + atomic rename). The indent matches the on-disk format amux uses for every metadata file, so callers no longer repeat the marshal-then-WriteFile dance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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