atomicfile

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package atomicfile writes files that readers find whole, or not at all.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Restore

func Restore(files []Saved, pattern string) error

Restore puts files back as they were, the last changed first: it writes back what they held, through temporary files named after pattern, and removes those that didn't exist. It returns what it couldn't put back.

func Write

func Write(dir, pattern, path string, data []byte) error

Write writes data to path through a temporary file of dir, named after pattern as os.CreateTemp names it, renamed into place: a reader finds the file whole, or not at all. A write that fails removes the temporary file. dir is on the file system of path, such as its directory. Others may read the file.

func WritePerm

func WritePerm(dir, pattern, path string, data []byte, perm fs.FileMode) error

WritePerm is like Write, but gives the file perm, such as 0o600 for a file only its user reads.

Types

type Saved

type Saved struct {
	// contains filtered or unexported fields
}

Saved is a file a change is about to write or remove, and what it held before, which Restore puts back.

func Backup

func Backup(path string) (Saved, error)

Backup returns what the file at path holds now: its content, or that there is none.

Jump to

Keyboard shortcuts

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