fsatomic

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package fsatomic provides a crash-durable atomic file write.

The common "write a temp file then rename over the target" idiom gives atomicity (a reader sees either the old or the new file, never a torn one), but NOT durability: without an fsync, a power loss or kernel crash can land the rename in the directory while the file's data is still only in the page cache, leaving an empty or truncated file after reboot. For data the agent can't reconstruct — conversation sessions, extracted memories — that is silent data loss.

WriteFile closes the gap: it fsyncs the file data before the rename and fsyncs the parent directory after, so a successful return means the bytes are durably on disk. It also uses a unique temp name, so two concurrent writers to the same target can't clobber each other's temp file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

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

WriteFile atomically and durably writes data to path with the given perm. On success the bytes are fsynced to disk and the rename is durable.

Types

This section is empty.

Jump to

Keyboard shortcuts

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