atomicpaths

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

atomicpaths

Go module implementing safe atomic directory access.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExhausted = errors.New("exhausted")

	// ErrCommitted states the given file was already committed.
	ErrCommitted = errors.New("already committed")

	// ErrRolledBack states commit was used after the file was
	// already rolled back.
	ErrRolledBack = errors.New("rolled back")
)

Functions

This section is empty.

Types

type Dir

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

Dir represents a temporary directory that can on success be "committed" to the provided path and rolled back otherwise.

func CreateDir

func CreateDir(origPath string, perm fs.FileMode) (*Dir, error)

func (*Dir) Close

func (d *Dir) Close() error

Close closes the Dir instance, removing any uncommitted temporary files.

func (*Dir) Commit

func (d *Dir) Commit() error

Commit commits the temporary directory to the original path by deleting the original path, if necessary, and moving the temporary directory to the original's path location.

func (*Dir) Name

func (d *Dir) Name() string

Name returns the path to the temporary directory to be modified.

func (*Dir) OriginalPath

func (d *Dir) OriginalPath() string

OriginalPath returns the path to the original directory.

type File

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

File represents a temporary file that on success can be "committed" to the provided path and rolled back otherwise.

func CreateFile

func CreateFile(origPath string, perm os.FileMode) (*File, error)

CreateFile creates a temporary file that can be either atomically committed to the given path or discarded.

func (*File) Close

func (f *File) Close() error

Close closes the File instance, removing any uncommitted temporary files.

func (*File) Commit

func (f *File) Commit() error

Commit flushes all unwritten changes to disk, closes the underlying temporary file, making it impossible to apply any changes, and commits the temporary file to the original path.

Commit can be called repeatedly in case of an error to resolve the returned problem and try again until the changes have been committed successfully or abandoned.

func (*File) OriginalPath

func (f *File) OriginalPath() string

OriginalPath returns the path to the original file.

Jump to

Keyboard shortcuts

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