atomicfile

package
v1.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package atomicfile writes files atomically so that a reader never observes a partially written file. It is used for the repo cache and the config, where an interrupted in-place write (crash, SIGKILL, power loss, or a full disk) would otherwise truncate the file and silently destroy data that cannot be regenerated, such as frecency history.

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 writes data to path atomically. It writes to a temporary file in the same directory, sets the requested permissions, then renames it over path. Rename is atomic on POSIX, so a concurrent reader sees either the complete old file or the complete new one, never a partial write. On any failure before the rename, path is left untouched and the temp file is removed.

It deliberately does not fsync. The guarantee is no-torn-file, not durability-of-the-latest-write: after a crash a reader may see the previous complete contents, which is the safe failure mode for a rebuildable cache.

Types

This section is empty.

Jump to

Keyboard shortcuts

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