atomicfile

package
v1.10.10 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package atomicfile provides symlink-preserving atomic file writes for user-managed config files.

WriteFile writes to a temp file in the destination's directory and renames it into place. When the destination path is a symlink, the real target is resolved first and the write lands on that target, so the symlink itself is preserved — a dotfiles-managed ~/.claude/settings.json stays a symlink.

This is the OPPOSITE of the intentional behavior in internal/credrefresh.atomicWriteFile, internal/session.atomicWriteFile (worker_scratch.go), and internal/session.writeFileDurable (inbox.go), which replace a symlink at the path with a regular file. Those helpers target agent-deck's own internal state and must not be consolidated here.

The package imports only the standard library so any internal package can depend on it without import cycles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

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

WriteFile atomically writes data to path, preserving a symlink AT path. If path is a symlink, the write targets the resolved real file and the link is left intact. For a regular or new file it behaves like a temp-file + rename. perm is applied to the written file.

Writing across filesystems via a symlink is unsupported: os.Rename cannot cross filesystems, so a symlink whose target lives on a different filesystem than the link returns an explicit error rather than silently falling back to a non-atomic write.

func WriteFileDurable

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

WriteFileDurable behaves like WriteFile but adds crash durability: the temp file is fsync'd before the rename and the target's parent directory is best-effort fsync'd after, so both the file contents and the rename survive a power loss. Use it for files where a torn or lost write on crash matters (for example agent-deck's own config.toml). The symlink-preserving resolution is identical to WriteFile.

Types

This section is empty.

Jump to

Keyboard shortcuts

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