filetxn

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 8 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 filetxn provides staged replacement for regular files.

Index

Constants

This section is empty.

Variables

View Source
var ErrReadChanged = errors.New("read target changed while opening")

ErrReadChanged means two regular-file identities differed during open. Callers reading atomic checkpoints may retry, but must revalidate the path.

Functions

func Append

func Append(path string, data []byte, mode os.FileMode) error

Append writes data to a regular file without following symlinks or writing through a hard link. Single-link files retain O_APPEND behavior; hard-linked files are copied and atomically replaced at path.

func OpenRegular

func OpenRegular(path string) (*os.File, error)

OpenRegular opens path for reading only when both the preflight target and opened file are the same regular file. The caller owns the returned file.

func OpenRegularInRoot

func OpenRegularInRoot(root, name string) (*os.File, error)

OpenRegularInRoot opens name only when it remains beneath root and the opened file is the same regular file visible at that project-relative path. The caller owns the returned file.

func ReadRegular

func ReadRegular(path string) ([]byte, error)

ReadRegular reads path only after OpenRegular validates its identity.

func Replace

func Replace(path string, data []byte, mode os.FileMode) error

Replace writes data to a sibling staging file and installs it at path. Existing regular files stay in place until the staged file replaces them.

func ReplaceAll

func ReplaceAll(outputs []Output) error

ReplaceAll validates every target before changing any of them, then replaces each file. If a later replacement fails, earlier files are restored.

func ReplaceAllThen

func ReplaceAllThen(outputs []Output, commit func() error) error

ReplaceAllThen replaces every output, runs commit, and restores every output to its prior state if commit fails.

func ReplaceFromReader

func ReplaceFromReader(path string, source io.Reader, mode os.FileMode) error

ReplaceFromReader streams source to a sibling staging file and installs it at path only after the complete stream has been written and closed.

Types

type Output

type Output struct {
	Path string
	Data []byte
	Mode os.FileMode
}

Output describes one file in an all-or-rollback replacement.

Jump to

Keyboard shortcuts

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