atomicfile

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package atomicfile replaces a file by writing a staged sibling and renaming it over the target, so readers see either the old file or the complete new one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	*os.File
	// contains filtered or unexported fields
}

File is a staged replacement for a target path. Write to it, then call CloseAtomicallyReplace. Defer Cleanup to remove the staged file on any path that does not reach the replace. A process that exits before either leaves the staged file in the target's directory, and nothing removes it later.

func Create

func Create(target string) (*File, error)

Create stages a replacement for target in target's directory. The staged name is random and created exclusively, so another account that can write to the directory can neither pre-create it nor learn it in advance. Its permissions are the existing target's when the target is a regular file, and 0644 otherwise, both narrowed by the umask: replacing a file never widens its mode.

func (*File) Cleanup

func (f *File) Cleanup()

Cleanup closes and removes the staged file unless CloseAtomicallyReplace succeeded. It removes nothing else.

func (*File) CloseAtomicallyReplace

func (f *File) CloseAtomicallyReplace() error

CloseAtomicallyReplace syncs and closes the staged file and renames it over the target.

Jump to

Keyboard shortcuts

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