feat(core): atomic file writes for corruption-sensitive paths (closes #84) - #184
Open
Galmanus wants to merge 1 commit into
Open
feat(core): atomic file writes for corruption-sensitive paths (closes #84)#184Galmanus wants to merge 1 commit into
Galmanus wants to merge 1 commit into
Conversation
…b#84) Extract the temp-file + rename pattern from writeArtifacts into a shared fs/atomic-write-file.ts helper and route the writes where a torn file breaks things through it: caatinga.artifacts.json, the frontend package.json (ensureBufferDependency), the frontend env file (syncFrontendEnv), the bindings freshness marker (writeBindingMarker), and template variable substitution. The helper creates parent dirs and unlinks the temp file on failure. Deliberately NOT converted: the scaffold writes in create-zk-project / create-minimal-project use flag 'wx' (exclusive create — refuse to overwrite unless --force), a different, intentional semantic that atomic overwrite-by- rename would break. (The patch-generated-binding-package path in the issue no longer exists.) Tests: atomic write leaves no temp file, creates missing parents, and cleans up the temp file on a failed commit.
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.
Closes #84
Only
writeArtifactsused the atomic temp-file + rename pattern; every other corruption-sensitive write used a directwriteFile, so a crash mid-write could leave a torn file (worst case: a brokenpackage.json).Fix: extracted a shared
fs/atomic-write-file.ts(atomicWriteFile— writes a unique temp file in the same dir, then atomicallyrenames it into place; creates parent dirs; unlinks the temp on failure) and routed the writes that matter through it:atomicWriteFileextracted fromwriteArtifacts(which now uses it)writeBindingMarker→ atomicsyncFrontendEnv→ atomicensureBufferDependency(package.json — highest priority) → atomiccreate-project-from-template) → atomicIntentionally left as-is: the scaffold writes in
create-zk-project/create-minimal-projectuseflag: force ? "w" : "wx"—wxis exclusive create (refuse to overwrite an existing file unless--force). Atomic overwrite-by-rename would silently defeat that guard, so converting them would be a regression, not a fix. (Thepatch-generated-binding-package.tspath listed in the issue no longer exists in the tree.)tsc --noEmit+ the artifacts / bindings / frontend / templates suites pass.