Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.