Repository navigation
Releases
v0.7.0
go-atomic-write v0.7.0
No breaking changes — a drop-in upgrade from v0.6.2.
New API: WriteFuncWithPerm
func WriteFuncWithPerm(path string, fn func(io.Writer) error, perm fs.FileMode) errorStreaming atomic writes with an explicit file permission. WriteFunc always inherited the existing file's mode (or the 0o644 default for new files), so streamed exports like a PII journal dump could only land 0644 unless callers chmod'd after the fact — racy, or with a visible wrong-mode window. The new variant creates the staged temp file with the requested mode, so the final file appears atomically with the correct permissions. Parameter order follows the package convention of putting the distinguishing argument last (WriteFuncVerified(path, fn, fp), WriteWithPerm(path, data, perm)).
Fixed: missing parent directories are created on write
Every write entrypoint now runs MkdirAll on the target's parent directory before staging, so a first write into a fresh cache or config directory succeeds instead of failing with no such file or directory at temp-file creation. Found in the wild: two consumer caches silently ENOENT'd on every save for weeks on machines where the deploy unit had not pre-created the directory. Concurrent MkdirAll on the same directory is safe and is exercised by the concurrency tests.
Also in this release
- Deterministic collision test for the temp-path uniqueness contract (injectable suffix seam; 512 concurrent real writers pinned from both sides).
- Website: docs now cover both
*Permvariants; landing redesign ("the commit ledger"); sitemap postbuild gate. - Docs/CI: release + deploy runbooks in CONTRIBUTING; docs-gates battery wired into CI; fleet-bump vendor-sync ordering fix; website CI lockfile drift guard.
Full changelog: see CHANGELOG.md ([0.7.0] - 2026-11-23) or the live changelog at https://atomicwrite.lars.software/changelog
v0.6.2 — website quality batch
Website/CI/docs release. Go code is unchanged since v0.6.1 — no API or behavior change; consumers can bump freely.
Headline fix
The hash-based CSP had silently blocked every allow-listed inline script since v0.4.0 (3.5 months): hash sources were emitted unquoted, browsers ignored them, and Starlight's theme pickers, sidebar state, and search shortcut never executed. Now fixed, asserted at build time, and covered by regression tests. The newsletter form (blocked by form-action since v0.4.0) works again.
Also in this release
- Mobile overflow fixed (310 px at 320 px viewport) and light-mode contrast audited to WCAG AA
- CI gates: hero parity, WCAG contrast audit, internal link checker, build-script regression tests, gitleaks, Playwright smoke suite (copy payloads, FAQ, 320 px, animation binding), Lighthouse budgets
- PR preview channels — every non-fork PR deploys an ephemeral Firebase preview
- Brand: PNG raster pipeline (2× lockups, GitHub social preview, contact sheet),
brand-tokens.jsonsingle palette source, documented usage rules - Docs: "When not to use" guide, full FAQ, platform-support matrix, config-reloader use case, CONTRIBUTING release/deploy runbooks, deploy-secret posture decision
Full notes in the changelog.
v0.6.1 — Temp-File Leak Fix & Brand Identity
Patch release: fixes a temp-file leak in the Go module, ships the new brand identity, and hardens CI.
Go module
Fixed
- Temp file leaked when the final rename failed — every public writer returned the rename error without removing the staged
.<random>.tmpfile (reachable when the target path is a directory, or on renameENOSPC/EIO). A failed write no longer leaves.tmpresidue next to the target.
Changed
- Source split into focused files —
atomicwrite.go(public write API),fingerprint.go(xxhash64 fingerprinting),commit.go(verification + locking + rename commit),stage.go(temp-file staging + fsync). No API or behavior change; all 31 tests moved verbatim.
Website
- Brand identity: "the atomic swap" logo — an emerald squircle with two opposing arrows (new bytes in, old bytes out), generated from a single geometry into every surface (favicon, header/footer, docs, OG card, README lockups).
pnpm run brand:checkgates drift in CI. - npm dependency sweep — open advisories 62 → 1 (the remaining moderate is dev-only and tracked upstream).
- Removed the stale
global.out.cssartifact and the rootpackage.jsonstub.
CI
- Cross-compile job (
windows/amd64,darwin/amd64,darwin/arm64) — the v0.5.1 Windows-break class is caught before a tag ships. govulncheck+ drift-guard jobs (go mod tidy -diff, version-trio check,pnpm install --frozen-lockfile).GOTOOLCHAIN: local— no rogue toolchain downloads.- golangci-lint pin
v2.13.2→v2.14.0— the go1.26-built binary could not typecheck the Go 1.27 stdlib.
Full changelog: v0.6.0...v0.6.1
v0.5.2
Maintenance release — dependency and toolchain bumps, CI repairs. No API changes.
Changed
- Go toolchain 1.26.5 → 1.26.7 (
go.modand.golangci.ymlaligned) gofrs/flockv0.13.0 → v0.13.1,golang.org/x/sys(indirect) v0.47.0 → v0.48.0golangci-lintconfig realigned to the v2.x schema; now-unnecessary//nolint:goseccomments removed
Fixed (website & CI)
- Firebase HTML cache rule now covers cleanUrls pages (was falling back to
max-age=3600— stale-content bug class) - Website deploy pipeline repaired (corepack/pnpm ordering, pinned tooling)
astro checkpinned to TypeScript 6.x (TS 7 drops the programmatic API it needs)- CI lint gate upgraded to
golangci-lint-actionv7 (v6 cannot install golangci-lint v2)
Added (CI)
- Dependabot config: weekly grouped minor/patch updates, capped at 5 open PRs per ecosystem
Upgrade: go get github.com/larsartmann/go-atomic-write@v0.5.2 — drop-in, no code changes required.
v0.4.0
⚠️ Breaking API split (source-incompatible)
The previous Write(path, data, fingerprint) mixed two distinct intents behind a zero-value Fingerprint{}, which silently skipped TOCTOU verification (a footgun). The API is now split by intent:
Write(path, data)/WriteFunc(path, fn)— plain atomic write, no TOCTOU check (the common case).WriteVerified(path, data, fingerprint)/WriteFuncVerified(path, fn, fingerprint)— atomic write WITH fingerprint verification. A zero-value fingerprint here means "the file must NOT already exist" — a concurrent creation is treated as a conflict and fails, rather than being silently ignored.
This is a source-incompatible change for 0.x (hence the minor bump). All in-repo consumers were updated.
Migration
| Before | After |
|---|---|
Write(path, data, Fingerprint{}) |
Write(path, data) |
Write(path, data, fp) (real fingerprint) |
WriteVerified(path, data, fp) |
WriteFunc(path, fn, Fingerprint{}) |
WriteFunc(path, fn) |
WriteFunc(path, fn, fp) (real fingerprint) |
WriteFuncVerified(path, fn, fp) |
✨ Added
WriteIfChanged(path, data) (changed bool, err error)— writes only if content differs from disk. Returnschanged=truewhen the file was written,falsewhen skipped (identical content). The idiomatic primitive for config-file writers and code generators that must not produce spurious diffs on re-runs: no content change means no file mutation, no mtime bump, no file-watcher trigger. ComposesFingerprintFile+WriteVerified; first-write uses plainWrite.
📝 Full changelog
See CHANGELOG.md for the complete list of changes in this release, including website, documentation, accessibility, and CI improvements.
v0.3.0 — WriteFunc Streaming API
What's New
WriteFunc — streaming atomic writes
A new public API for writing large or incrementally-produced content without holding the full payload in memory:
err := atomicwrite.WriteFunc(path, func(w io.Writer) error {
enc := json.NewEncoder(w)
return enc.Encode(largeObject)
}, fp)The callback receives a bufio.Writer (64KB buffer). The temp file is fsync'd before atomic rename, and TOCTOU fingerprint verification works identically to Write.
Other changes
- Benchmark data generation extracted into a shared
benchDatahelper .gitattributesfor cross-platform line-ending normalization- Marketing website launched at atomicwrite.lars.software
Full changelog: CHANGELOG.md
v0.2.0 — Restored Atomicity & Crash Durability
The release that made "atomic-write" actually atomic
v0.1.0 shipped with a .bak two-rename pattern that opened a window where the target file didn't exist. A concurrent reader could see ENOENT, and a crash between the two renames left the target missing. The library named "atomic-write" was not atomic.
v0.2.0 fixes this with a single rename(2) on POSIX, adds fsync for real crash durability, and gives each concurrent writer a unique temp file to prevent byte interleaving.
Fixed
- Removed
.baktwo-rename pattern — the oldatomicRenamedidpath→.bakthentmp→path, opening a window where the target didn't exist. Now a singleos.Rename(tmp, path)is one atomic syscall on POSIX and atomically replaces on Windows viaMoveFileEx. - Concurrent writer corruption —
tmpPathwas computed before the lock (path + ".tmp"), so two concurrentWrite()calls to the same target both truncated and wrote the same staging file, interleaving bytes. Now each writer gets a unique temp file viacrypto/randsuffix. - Concurrency test couldn't catch the bug —
TestConcurrentWriteRACEused identical content from all writers, so byte interleaving was undetectable. Rewritten with 10 writers using divergent content plus an integrity check. - "Crash safety" doc claim was false — no
fsyncwas called anywhere. NowwriteAndSync()opens the temp file, writes data, callsfile.Sync(), and closes. On POSIX, the target directory is alsofsync'd after rename.
Added
fsyncfor crash durability — temp file is fsync'd before rename; target directory is fsync'd after rename (POSIX only)- Unique temp file names —
crypto/rand4-byte hex suffix prevents concurrent writer staging-file corruption - Platform-specific rename — split into
rename_unix.go(singlerename(2)+ directoryfsync) andrename_windows.go(retry loop onERROR_ACCESS_DENIED/ERROR_SHARING_VIOLATION, 5 retries with exponential backoff) writeAndSync(),randomSuffix(),syncDir()internal functionsTestWriteLeavesNoLeftoverFiles— verifies no.bakand no.tmpfiles remain after a successful write
Changed
Write()now stages to a unique temp file instead of a sharedpath + ".tmp"atomicRename()no longer creates.bakfiles — singleos.Renamereplaces atomicallyTestConcurrentWriteRACErewritten: 10 writers, divergent content, integrity check
Removed
TestWriteCreatesBackup— tested the.bakpattern as a feature; the pattern was a bug.bakfile creation — no longer created alongside the target
Caveats
- Windows rename retry loop compiles via build tags but is untested on real Windows hardware
- No POSIX-equivalent directory fsync on Windows
- No stale temp file cleanup — crashed writes leave
.tmpfiles (unique names prevent interference but don't self-clean)
Full Changelog: v0.1.1...v0.2.0
v0.1.1
What's Changed
Changed
- LICENSE changed from PROPRIETARY to MIT — the README already stated MIT; the LICENSE file now matches
- Comprehensive
.golangci.ymllint configuration added - Test and benchmark code quality improvements for lint compliance
- Documentation formatting and accuracy fixes across all
.mdfiles
Fixed
*.bakadded to.gitignore— backup files from atomic writes were showing as untrackederrcheck: explicit discard ofhasher.Writereturn value in streaming benchmarks
Full Changelog: v0.1.0...v0.1.1
v0.1.0 — Initial Release
TOCTOU-safe file writes for Go
Initial release providing race-free file writes via xxhash64 fingerprint verification, cross-platform file locking, and atomic rename.
Added
- TOCTOU-safe file writes via xxhash64 fingerprint verification
- Cross-platform file locking (
flockon Unix,LockFileExon Windows) viagofrs/flock - Atomic rename with
.bakbackup of previous content Fingerprinttype ([8]byte) withIsZero()andMatches()methodsFingerprintFile— computes fingerprint from file path (zero-value for nonexistent files)FingerprintFromBytes— computes fingerprint from raw bytesWrite(path, data, fingerprint)— main API with TOCTOU protectionErrConcurrentModificationsentinel error for fingerprint mismatch detection- File permission preservation from existing file (defaults to
0644for new files) - xxhash64 vs SHA-256 benchmarks demonstrating ~11× speed advantage
- Unit tests, permission preservation tests, and concurrent writer contention test
Note: The
.baktwo-rename pattern in this release was later found to be non-atomic. It was fixed in v0.2.0.