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 ¶
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 ¶
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.