Documentation
¶
Overview ¶
Package filetxn provides staged replacement for regular files.
Index ¶
- Variables
- func Append(path string, data []byte, mode os.FileMode) error
- func OpenRegular(path string) (*os.File, error)
- func OpenRegularInRoot(root, name string) (*os.File, error)
- func ReadRegular(path string) ([]byte, error)
- func Replace(path string, data []byte, mode os.FileMode) error
- func ReplaceAll(outputs []Output) error
- func ReplaceAllThen(outputs []Output, commit func() error) error
- func ReplaceFromReader(path string, source io.Reader, mode os.FileMode) error
- type Output
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
ReadRegular reads path only after OpenRegular validates its identity.
func Replace ¶
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 ¶
ReplaceAll validates every target before changing any of them, then replaces each file. If a later replacement fails, earlier files are restored.
func ReplaceAllThen ¶
ReplaceAllThen replaces every output, runs commit, and restores every output to its prior state if commit fails.