atomicfile

package
v0.66.16 Latest Latest
Warning

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

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

Documentation

Overview

Package atomicfile provides a crash-safe file write primitive: write to a temp file in the target directory, fsync it, atomically rename it into place, then fsync the parent directory. A crash at any point leaves either the old file fully intact or the new file fully written — never a truncated or partially-written file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(path string, data []byte, perm os.FileMode) error

Write atomically writes data to path with the given permissions. The parent directory is created (mode 0o700) if it does not exist. The temp file is created in the same directory as path so the final rename stays on one filesystem (a cross-device rename would fail and is not atomic).

When Write has to create parent directories, it fsyncs each one's parent after the write so the whole new path is durable — not just the leaf. Without this, a crash could lose a freshly-created directory even though the file's own data was synced.

Types

This section is empty.

Jump to

Keyboard shortcuts

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