atomicfile

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package atomicfile writes files atomically: content is written to a temporary file in the same directory as the destination, then renamed into place. A write that fails partway through (a full disk, a killed process, a crash) leaves the temp file incomplete but never touches the destination, so a good previous artifact is never truncated or corrupted by a failed overwrite — os.Create alone truncates the destination immediately, before a single byte of the new content is written.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(path string, perm os.FileMode, write func(io.Writer) error) error

Write creates parent directories for path as needed, calls write with a temporary file in the same directory, and renames it into place at path only if write and the subsequent close both succeed. perm sets the final file's permissions. A same-directory temp file guarantees the rename is on the same filesystem, so it's atomic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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