safe

package
v1.87.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyDone is returned when the safe file has already been closed
	// or committed
	ErrAlreadyDone = errors.New("safe file was already committed or closed")
)

Functions

This section is empty.

Types

type FileWriter

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

FileWriter is a thread safe writer that does an atomic write to the target file. It allows one writer at a time to acquire a lock, write the file, and atomically replace the contents of the target file.

func CreateFileWriter

func CreateFileWriter(path string) (*FileWriter, error)

CreateFileWriter takes path as an absolute path of the target file and creates a new FileWriter by attempting to create a tempfile

func (*FileWriter) Close added in v1.55.0

func (fw *FileWriter) Close() error

Close will close and remove the temp file artifact if it exists. If the file was already committed, an ErrAlreadyClosed error will be returned and no changes will be made to the filesystem.

func (*FileWriter) Commit

func (fw *FileWriter) Commit() error

Commit will close the temporary file and rename it to the target file name the first call to Commit() will close and delete the temporary file, so subsequently calls to Commit() are gauaranteed to return an error.

func (*FileWriter) Write

func (fw *FileWriter) Write(p []byte) (n int, err error)

Write wraps the temporary file's Write.

Jump to

Keyboard shortcuts

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