Documentation
¶
Overview ¶
Package atomicfile 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 Chmod ¶
Chmod sets the mode of path. Inside a trace, it is a span, file.chmod, with the path and the mode.
func Remove ¶
Remove removes path. Inside a trace, it is a span, file.remove, with the path. A path that is not there is not an error of the span: the caller decides what it means.
func Write ¶
func Write( ctx context.Context, vfs avfs.VFS, path string, content []byte, mode fs.FileMode, ) error
Write 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.
Inside a trace, the write is a span, file.write, with the path, the mode and the size; the content stays out of it. A caller writes only a file whose content differs, so the span is a change. A write outside a trace, such as the keys at startup, makes no span.
Types ¶
This section is empty.