atomicfile

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package atomicfile replaces a file atomically. It is the one implementation behind fsx.WriteFile and secret.WriteFile, which word its errors each in their own way.

Index

Constants

This section is empty.

Variables

View Source
var ErrSymlink = errors.New("is a symbolic link")

ErrSymlink reports a symbolic link at the path to write.

Functions

func Write

func Write(path string, data []byte, perm fs.FileMode, pattern string) error

Write writes data to path through a temporary file in the same directory, named after pattern as os.CreateTemp reads it, and renames it into place, so a reader sees the old contents or the new ones, never part of either. The temporary file gets mode perm before any data reaches it; outside Windows a failure to set it is an error, on Windows it is ignored, since only the read-only bit can be set there. The data is synced to disk before the rename.

The directory must exist. A symbolic link at path is refused with ErrSymlink. Errors are returned as the os package returns them; the caller adds the path and its prefix.

Types

This section is empty.

Jump to

Keyboard shortcuts

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