refactor: consolidate atomic-write primitives onto fsutil (iss-32) - #44
Merged
Conversation
Four divergent temp-file+rename copies and a duplicate isRealDir are routed through the canonical internal/fsutil, behind a detector: - fsutil gains WriteFileAtomicPreserveMode (stat existing mode, default 0644, delegate to WriteFileAtomic). - ahoy marker.go writeFileAtomic + store.go isRealDir deleted; callers use fsutil.WriteFileAtomicPreserveMode / fsutil.IsRealDir. - capture roots.go writeFileAtomic deleted; callers use fsutil. - memory durableWrite replaced by a one-line writeStringAtomic adapter over fsutil.WriteFileAtomic; orphaned tmpCounter var + sync/atomic import removed. - TestNoNonCanonicalAtomicWritePrimitives flags any named redefinition outside fsutil; a new fsutil crash-safety suite covers the primitive (fsutil previously had zero tests). Behaviour: the ahoy and capture writers GAIN a parent-directory fsync (a durability strengthening; their copies never did it). Memory pages are now written at an explicit 0644 chmod where the old writer left the mode subject to the process umask (0644 under the default 022; formerly 0600 under a 077 umask) — deterministic and consistent with every other abcd store file. Symlink-refusal and same-directory atomic rename are unchanged; os.CreateTemp's random name is stronger than the old fixed temp path. security-reviewed PASS, ruthless-reviewed PROMOTE. A fifth inline copy (memory/ingest.go storeOriginal), outside this issue's named corpus, is tracked as iss-79. Assisted-by: Claude:claude-opus-4-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves ledger issue iss-32
atomic-write-consolidation— one-canonical-primitive.Before
Four independent temp-file+rename atomic-write implementations with divergent durability, plus a duplicated
isRealDir:internal/fsutil.WriteFileAtomicahoy/marker.go writeFileAtomiccapture/roots.go writeFileAtomicmemory/writer.go durableWriteahoy/store.go isRealDirfsutil.IsRealDirinternal/fsutilitself had zero tests.After — detector-first
TestNoNonCanonicalAtomicWritePrimitives(fsutil) walksinternal/and fails on any namedwriteFileAtomic/durableWrite/isRealDiroutside fsutil. Watched fail (flagged all four) → green after consolidation.IsRealDirsymlink refusal.fsutilgainsWriteFileAtomicPreserveMode; ahoy/capture callers route to it (same(path, []byte)signature); memory'sdurableWritebecomes a one-linewriteStringAtomicadapter overfsutil.WriteFileAtomic. Deleted the four copies; removed the orphanedtmpCounter+sync/atomic.Behaviour deltas (documented, not smuggled)
capture/roots.go's doc had already claimed it).0644chmod where the old writer left the mode subject to the process umask (identical under the default 022; formerly0600under a 077 umask). Deterministic and consistent with every other abcd store file.os.CreateTemp's random name is stronger than the old fixed temp path.Review
O_EXCL→CreateTempat least as strong, no permission downgrade, temp stays in the target dir (atomic rename).make preflightclean (build, gofmt, vet, test,-race).Scope note
A fifth inline durable-write (
memory/ingest.go storeOriginal) is outside this issue's named 4-copy corpus and is inline (the named-function detector can't catch it); it is filed as iss-79 rather than claimed consolidated.Branches from
main(independent of the open #43). Do not merge / no auto-merge — maintainer merges.Assisted-by: Claude:claude-opus-4-8