atomicwrite

package
v0.31.73 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package atomicwrite provides crash-safe file writes for TARS state files. Callers pass the full intended bytes; the helper writes a sibling temp file, fsyncs and closes it, then renames it over the destination. A crash before the rename leaves the previous file content untouched; a crash after means the new content is fully on disk. There is never a half-written file at the destination path.

This is the canonical persistence helper for sessions.json, jobs.json, knowledge notes, the semantic index, and similar long-lived state. Callers that need extra behavior (chmod, Windows rename retry, JSON marshaling) should layer on top of Write rather than reinvent the temp+rename pattern.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(path string, data []byte) error

Write writes data atomically to path. The parent directory is created with 0o755 if missing. The created file has the default 0o600 permissions from os.CreateTemp; callers needing a specific mode should chmod the destination after Write returns, or use a helper that wraps this with the desired bits (see internal/tool/write_file.go for one such wrapper).

Atomicity is provided by os.Rename, which is atomic on POSIX. On Windows os.Rename can fail when the destination already exists; callers targeting Windows should use the wrapper in internal/tool/write_file.go which carries a remove-then-rename fallback.

Types

This section is empty.

Jump to

Keyboard shortcuts

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