Skip to content

Releases

v0.7.0

Choose a tag to compare

@LarsArtmann LarsArtmann released this 23 Nov 01:59

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) error

Streaming 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 *Perm variants; 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

Choose a tag to compare

@LarsArtmann LarsArtmann released this 04 Nov 16:37

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.json single 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

Choose a tag to compare

@LarsArtmann LarsArtmann released this 04 Nov 01:59

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>.tmp file (reachable when the target path is a directory, or on rename ENOSPC/EIO). A failed write no longer leaves .tmp residue 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:check gates drift in CI.
  • npm dependency sweep — open advisories 62 → 1 (the remaining moderate is dev-only and tracked upstream).
  • Removed the stale global.out.css artifact and the root package.json stub.

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

Choose a tag to compare

@LarsArtmann LarsArtmann released this 17 Sep 07:44

Maintenance release — dependency and toolchain bumps, CI repairs. No API changes.

Changed

  • Go toolchain 1.26.5 → 1.26.7 (go.mod and .golangci.yml aligned)
  • gofrs/flock v0.13.0 → v0.13.1, golang.org/x/sys (indirect) v0.47.0 → v0.48.0
  • golangci-lint config realigned to the v2.x schema; now-unnecessary //nolint:gosec comments 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 check pinned to TypeScript 6.x (TS 7 drops the programmatic API it needs)
  • CI lint gate upgraded to golangci-lint-action v7 (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

Choose a tag to compare

@LarsArtmann LarsArtmann released this 26 Jul 18:03

⚠️ 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. Returns changed=true when the file was written, false when 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. Composes FingerprintFile + WriteVerified; first-write uses plain Write.

📝 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

Choose a tag to compare

@LarsArtmann LarsArtmann released this 23 Jul 16:59

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 benchData helper
  • .gitattributes for cross-platform line-ending normalization
  • Marketing website launched at atomicwrite.lars.software

Full changelog: CHANGELOG.md

v0.2.0 — Restored Atomicity & Crash Durability

Choose a tag to compare

@LarsArtmann LarsArtmann released this 11 Jul 20:18

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 .bak two-rename pattern — the old atomicRename did path→.bak then tmp→path, opening a window where the target didn't exist. Now a single os.Rename(tmp, path) is one atomic syscall on POSIX and atomically replaces on Windows via MoveFileEx.
  • Concurrent writer corruption — tmpPath was computed before the lock (path + ".tmp"), so two concurrent Write() calls to the same target both truncated and wrote the same staging file, interleaving bytes. Now each writer gets a unique temp file via crypto/rand suffix.
  • Concurrency test couldn't catch the bug — TestConcurrentWriteRACE used 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 fsync was called anywhere. Now writeAndSync() opens the temp file, writes data, calls file.Sync(), and closes. On POSIX, the target directory is also fsync'd after rename.

Added

  • fsync for crash durability — temp file is fsync'd before rename; target directory is fsync'd after rename (POSIX only)
  • Unique temp file names — crypto/rand 4-byte hex suffix prevents concurrent writer staging-file corruption
  • Platform-specific rename — split into rename_unix.go (single rename(2) + directory fsync) and rename_windows.go (retry loop on ERROR_ACCESS_DENIED/ERROR_SHARING_VIOLATION, 5 retries with exponential backoff)
  • writeAndSync(), randomSuffix(), syncDir() internal functions
  • TestWriteLeavesNoLeftoverFiles — verifies no .bak and no .tmp files remain after a successful write

Changed

  • Write() now stages to a unique temp file instead of a shared path + ".tmp"
  • atomicRename() no longer creates .bak files — single os.Rename replaces atomically
  • TestConcurrentWriteRACE rewritten: 10 writers, divergent content, integrity check

Removed

  • TestWriteCreatesBackup — tested the .bak pattern as a feature; the pattern was a bug
  • .bak file 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 .tmp files (unique names prevent interference but don't self-clean)

Full Changelog: v0.1.1...v0.2.0

v0.1.1

Choose a tag to compare

@LarsArtmann LarsArtmann released this 03 Jun 15:18

What's Changed

Changed

  • LICENSE changed from PROPRIETARY to MIT — the README already stated MIT; the LICENSE file now matches
  • Comprehensive .golangci.yml lint configuration added
  • Test and benchmark code quality improvements for lint compliance
  • Documentation formatting and accuracy fixes across all .md files

Fixed

  • *.bak added to .gitignore — backup files from atomic writes were showing as untracked
  • errcheck: explicit discard of hasher.Write return value in streaming benchmarks

Full Changelog: v0.1.0...v0.1.1

v0.1.0 — Initial Release

Choose a tag to compare

@LarsArtmann LarsArtmann released this 11 Jul 20:18

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 (flock on Unix, LockFileEx on Windows) via gofrs/flock
  • Atomic rename with .bak backup of previous content
  • Fingerprint type ([8]byte) with IsZero() and Matches() methods
  • FingerprintFile — computes fingerprint from file path (zero-value for nonexistent files)
  • FingerprintFromBytes — computes fingerprint from raw bytes
  • Write(path, data, fingerprint) — main API with TOCTOU protection
  • ErrConcurrentModification sentinel error for fingerprint mismatch detection
  • File permission preservation from existing file (defaults to 0644 for new files)
  • xxhash64 vs SHA-256 benchmarks demonstrating ~11× speed advantage
  • Unit tests, permission preservation tests, and concurrent writer contention test

Note: The .bak two-rename pattern in this release was later found to be non-atomic. It was fixed in v0.2.0.