atomicfile

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SyncDir

func SyncDir(dir string) error

syncDirAfterRename is the production post-rename step: fsync dir so the rename itself is durable. It is a no-op on Windows, where directory fsync is unsupported and rename is already journalled by NTFS.

func Write

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

writeFileAtomic replaces path with data so that a crash or power loss leaves either the old or the new file, never a truncated one: it writes a uniquely named temp file in the same directory (concurrent writers or a stale temp from a crash cannot collide), fsyncs it and renames it over path, then best-effort fsyncs the directory via syncDirAfterRename — a failure there only warns, since the rename already committed the new file.

func WriteWithDirSync

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

writeFileAtomicWithDirSync is writeFileAtomic with an injected post-rename dir-sync step (Store.syncDir). The injected step replaces syncDirAfterRename entirely, so tests exercise it on every platform, including Windows, without changing production Windows behaviour.

Types

This section is empty.

Jump to

Keyboard shortcuts

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