Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Grow ¶
Grow makes room for an additional n bytes at the end of slice s. Returns the complete resulting slice, and a sub-slice representing the newly-extended n-byte region, which the caller must initialize. Simply re-slices s in-place if it already has sufficient capacity; otherwise allocates a larger slice and copies the existing portion.
func IsRace ¶
Returns true if an error returned by Commit() indicates that the commit failed because a concurrent write was detected and the force flag was not specified.
Types ¶
type Replacer ¶
type Replacer struct { Name string // Name of the file being replaced Info os.FileInfo // Timestamp of target file before replacement File *os.File // Temporary file used for writing }
func (*Replacer) Abort ¶
func (r *Replacer) Abort()
Abort replacement by closing and deleting the temporary file. It is harmless to call Abort() after the Replacer has already committed or aborted: thus, the caller may wish to 'defer r.Abort()' immediately after Open().
func (*Replacer) Commit ¶
Attempt to commit the temporary replacement file to the target. On success, Close()s the temporary file and atomically renames it to the target filename saved in the Name field.
Returns an error if the target was modified by someone else in the time since the temporary file was created. In this case, the caller might for example call Abort() and create a new Replacer after accounting for the new modifications. Alternatively the caller might call ForceCommit() instead after warning the user that state might be lost and prompting for confirmation.
func (*Replacer) ForceCommit ¶
Commit the temporary replacement file without checking for concurrent modifications in the meantime.
func (*Replacer) Open ¶
Open a file to replace an existing file as safely as possible, attempting to avoid corruption on crash or concurrent writers.
Creates a new temporary file in the same directory as the target, but does not actually touch the target until Close() is called. The caller can also call Abort() to close and delete the temporary file without replacing the original file.
If r.Info is nil, sets it to the status of the target file at the time of this Open() call, for later race detection on Close(). The caller can pre-set r.Info to a different timestamp to define the race-detection window explicitly: e.g., using an earlier timestamp obtained when the original file was first read.
Something like this functionality might be useful to have in os.ioutil.