atomicfile

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package atomicfile replaces a file whole: a reader opening the path sees the previous content or the new, never a mix, and after a crash the path holds one of the two. It is the one home for that write in this tree; the house lint's ATOMIC-WRITE rule refuses a hand-rolled temporary file renamed into place anywhere else.

The write is github.com/google/renameio/v2 (a uniquely named temporary file, fsync, close, rename) with three choices renameio leaves open made for every caller:

  • The mode is exact. renameio.WriteFile keeps the mode of a file already at the path, so a secret once widened to 0644 would stay 0644 however often it is rewritten with 0600; here the mode given is the mode on disk, whatever was there and whatever the umask is.
  • The temporary file is created beside the target, never in $TMPDIR, so no write probes another mount and the rename never crosses one.
  • The directory is synced after the rename, so the new name, not only the new content, survives a crash.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

func WriteFile(path string, content []byte, mode os.FileMode) error

WriteFile replaces path with content at exactly mode. The directory must exist. Concurrent writers to one path never collide: each writes its own temporary file and the last rename wins whole. On failure nothing is left behind and whatever was at path is untouched.

Types

This section is empty.

Jump to

Keyboard shortcuts

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