atomicfile

package
v1.33.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package atomicfile writes small state files the way lerd's daemons need: atomically, and only when the content actually changed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteIfChanged

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

WriteIfChanged writes data to path via a unique temp file, an fsync and a rename, so a reader never sees a half-written file and a crash never loses a published one, and skips the write entirely when path already holds exactly these bytes.

The skip is the point. A daemon that re-persists a snapshot on a fixed tick spends a write, a rename and a dirtied page every tick even when nothing happened, which on a laptop keeps the disk and the writeback path from ever settling. Comparing against what is already there costs one read of a small, page-cached file. Reports whether it wrote.

Types

This section is empty.

Jump to

Keyboard shortcuts

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