atomicfile

package
v0.3.24 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 10 Imported by: 6 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 replaces files whole: the content goes to a uniquely named temporary file beside the target, which is synced and renamed over it. A reader sees the old file or the new one and never a partial write, a crash leaves one of the two complete, and concurrent writers never share a temporary. WriteFileDurable also syncs the directory, so once it returns the new file survives a power cut.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTemporary

func IsTemporary(path, candidate string) bool

IsTemporary reports whether candidate names a temporary a write of path uses, as a watcher of path's directory sees it come and go.

func Write

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

Write replaces path with what write produces, with permissions perm. On a failure path is untouched and the temporary is removed.

func WriteFile

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

WriteFile replaces path with data, as os.WriteFile but atomically.

func WriteFileDurable

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

WriteFileDurable is WriteFile for data the caller reports as stored, which must outlive a power cut: the directory is synced after the rename, so the replacement is on disk when it returns. A failure of that sync is reported with path already replaced.

func WriteSeekable

func WriteSeekable(path string, perm os.FileMode, write func(io.WriteSeeker) error) error

WriteSeekable is Write for a producer that seeks back over what it wrote, as a muxer patching its header does: write is handed the temporary itself, unbuffered.

Types

This section is empty.

Jump to

Keyboard shortcuts

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