Documentation
¶
Overview ¶
Package fsutil holds filesystem operations shared by providers that write files a running system depends on.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteFileAtomic ¶
WriteFileAtomic writes content to path so that a reader never sees a partial file: the content goes to a temporary file beside the target, is given the requested mode, and is then renamed over it. A rename within one directory is atomic, so the target is either the old file or the new one, never half of either.
The temporary file sits in the target's own directory because a rename across filesystems is not atomic, and /tmp is frequently its own filesystem. It is removed on every failure path, so a failed write leaves nothing behind.
The mode is set on the temporary file rather than on the target, so the content is never briefly readable by someone the mode excludes. It is set twice — at creation and again explicitly — because the mode passed to open is masked by the process umask and chmod is not.
Types ¶
This section is empty.