atomicfile

package
v0.1.46 Latest Latest
Warning

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

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

Documentation

Overview

Package atomicfile is the one way forge writes a file it generates or scaffolds.

os.WriteFile truncates the target and then writes it. A process that dies between the two — a sandbox restart in the middle of `forge generate` — leaves the file empty or partial, and a generated file that is empty is not "stale": it is a compile error in every package that imports it. WriteFile instead writes a sibling temp file, fsyncs it, and renames it over the target, so the target is always either the complete old bytes or the complete new bytes.

internal/writeguard fails the build on a direct os.WriteFile under internal/, so a new generator cannot reintroduce the truncating write.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

func WriteFile(path string, data []byte, perm fs.FileMode) error

WriteFile writes data to path atomically. It is a drop-in for os.WriteFile: a new file gets perm (subject to the umask); an existing regular file keeps its current permission bits and perm is ignored; a symlink is written through to its target. A path that exists but is not a regular file (a device, a FIFO) cannot be replaced by rename and is written in place.

On any error the target is untouched and the temp file is removed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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