Documentation
¶
Overview ¶
Package fsutil provides small filesystem helpers shared across packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotRegularFile = errors.New("not a regular file")
ErrNotRegularFile is returned by AtomicReplaceFile when path exists and is not a regular file: a symlink, a directory or a special file.
Functions ¶
func AtomicReplaceFile ¶ added in v1.1.0
AtomicReplaceFile is AtomicWriteFile for a path that must not be redirected: it never follows a symlink at path. It writes data to path atomically, as AtomicWriteFile does, when path does not exist or is a regular file (keeping its permission bits). It returns an error wrapping ErrNotRegularFile, without writing anything, when path is a symlink, directory or special file, and otherwise the errors of AtomicWriteFile.
func AtomicWriteFile ¶
AtomicWriteFile writes data to path using a write-to-temp-then-rename pattern in path's directory: readers see either the old content or the new one, never a half-written file, and the data and the rename are flushed to disk before it returns, so a crash or power loss leaves one of the two versions in place.
path is the destination file, data its full new content, and perm the mode for a newly created file. A path that is a symlink is written through to its target, keeping the link. An existing file keeps its permission bits; perm only applies to a newly created file, and is applied exactly (not masked by the umask). Missing parent directories are created private to the user (0700).
It returns an error when the path cannot be resolved, the directory or temporary file cannot be created, or writing, syncing, closing, chmod or renaming fails; the temporary file is removed in every failure case. A failure to sync the directory after the rename is ignored.
Types ¶
This section is empty.