fileutil

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWriteBytes added in v0.6.4

func AtomicWriteBytes(filePath string, data []byte, perm os.FileMode) error

AtomicWriteBytes writes raw bytes to filePath atomically using temp+rename, fsync'd before rename and the parent directory fsync'd after rename so the new inode entry survives a hard crash. Intended for user-facing files where a crash-window partial write would destroy content — instruction files (AGENTS.md / CONVENTIONS.md), env files, etc.

If filePath is a symlink, the rename follows the symlink to its target so the link itself is preserved and the underlying file is updated. The CLAUDE.md → AGENTS.md pattern that ox init creates depends on this — a naive rename would replace the symlink with a regular file and break the link. Ordinary (non-symlink) paths are written directly as before.

func AtomicWriteJSON

func AtomicWriteJSON(filePath string, data any, perm os.FileMode) error

AtomicWriteJSON writes data as JSON to filePath atomically using temp+rename. This prevents partial/corrupt files from concurrent reads during write. The file is fsync'd before rename to ensure durability.

Types

This section is empty.

Jump to

Keyboard shortcuts

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