atomicfile

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 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 writes state files so a crash or power loss leaves either the old or the new content, never a torn one, and moves unreadable state files aside instead of letting the next save overwrite them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Quarantine

func Quarantine(path string, cause error) error

Quarantine renames the unreadable file at path to <path>.corrupt-<unix seconds> (with a numeric suffix if that exists already) so nothing overwrites it, and returns a *CorruptError naming both. cause is the parse error.

func Write

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

Write replaces path with data atomically: a temporary file in the same directory is written, fsynced and renamed over path, then the directory is fsynced so the rename itself survives a crash. The directory must exist.

func WriteFunc

func WriteFunc(path string, perm fs.FileMode, fill func(io.Writer) error) (err error)

WriteFunc is Write for content produced by a writer (an encoder, for example).

Types

type CorruptError

type CorruptError struct {
	Path   string // the state file
	Backup string // where its content is kept now ("" if it could not be moved)
	Err    error  // why it could not be read (or moved)
}

CorruptError reports a state file that could not be parsed and was moved aside.

func (*CorruptError) Error

func (e *CorruptError) Error() string

func (*CorruptError) Unwrap

func (e *CorruptError) Unwrap() error

Jump to

Keyboard shortcuts

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