fsutil

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 5 Imported by: 0

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

func WriteFileAtomic(
	vfs avfs.VFS,
	path string,
	content []byte,
	mode fs.FileMode,
) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL