Help us shape the future of Go! Take the 2026 Go Developer Survey

fsutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package fsutil provides small filesystem helpers shared across packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWriteFile

func AtomicWriteFile(path string, data []byte, perm os.FileMode) error

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.

Jump to

Keyboard shortcuts

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