Documentation
¶
Overview ¶
Package fsutil provides small filesystem helpers shared across packages.
Index ¶
Constants ¶
const ( OpenNonblock = syscall.O_NONBLOCK OpenNoFollow = syscall.O_NOFOLLOW )
Open flags for reading a file a path may name a FIFO or a symlink in place of the regular file expected there. OpenNonblock keeps opening a FIFO with no writer from waiting forever (it has no effect on a regular file), and OpenNoFollow makes opening a symlink fail instead of following it.
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; a dangling symlink, whose target doesn't exist, is replaced by a regular file instead. 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.
func Rename ¶ added in v1.2.0
Rename renames oldpath to newpath like os.Rename. On Windows, a rename blocked by another process holding either file open (an antivirus scan, a reader) is retried for up to a second.
func SHA256File ¶ added in v1.2.0
SHA256File returns the lowercase hex SHA-256 digest of the file at path, or an error if it cannot be read.
Types ¶
This section is empty.