Documentation
¶
Overview ¶
Package atomicfile provides a crash-safe file write primitive: write to a temp file in the target directory, fsync it, atomically rename it into place, then fsync the parent directory. A crash at any point leaves either the old file fully intact or the new file fully written — never a truncated or partially-written file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Write ¶
Write atomically writes data to path with the given permissions. The parent directory is created (mode 0o700) if it does not exist. The temp file is created in the same directory as path so the final rename stays on one filesystem (a cross-device rename would fail and is not atomic).
When Write has to create parent directories, it fsyncs each one's parent after the write so the whole new path is durable — not just the leaf. Without this, a crash could lose a freshly-created directory even though the file's own data was synced.
Types ¶
This section is empty.