atomicfile

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package atomicfile is the one owner of stage-then-rename writes. The staging name must be unique per call: a fixed "<path>.tmp" let two concurrent savers of the same file truncate each other's staging copy, so half-written bytes could reach a credential document by rename (GDK-1233; GDK-1244 for the sites outside config). os.CreateTemp opens 0600 with O_EXCL — the mode every caller here wants — where os.WriteFile wrote through whatever already sat at the fixed name.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

func WriteFile(path, pattern string, data []byte) error

WriteFile stages data through a unique temp file beside path (same directory, so the rename stays on one filesystem) and renames it into place. pattern names the temp file the way os.CreateTemp takes it, e.g. "config-*.json". On any failure before the rename the staging file is removed; after it, the remove is a no-op on a name that no longer exists.

func WriteStream added in v0.22.0

func WriteStream(path, pattern string, fill func(io.Writer) error) error

WriteStream is WriteFile for content that is produced rather than held: fill hands the staging file, and only a nil return renames it into place. It exists so a writer whose content does not fit in memory — the migrate seed document, whose attachment bytes stream straight from the origin (GDK-1618) — still gets the same stage-then-rename guarantee.

Types

This section is empty.

Jump to

Keyboard shortcuts

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