Skip to content

fix(core): ensure parent directory exists in writeIfUnchanged#33096

Open
Robin1987China wants to merge 1 commit into
anomalyco:devfrom
Robin1987China:fix-writeifunchanged-dir
Open

fix(core): ensure parent directory exists in writeIfUnchanged#33096
Robin1987China wants to merge 1 commit into
anomalyco:devfrom
Robin1987China:fix-writeifunchanged-dir

Conversation

@Robin1987China

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #33075

Type of change

  • Bug fix

What does this PR do?

writeIfUnchanged in packages/core/src/file-mutation.ts wrote without ensuring the parent directory exists, unlike create which catches NotFound and calls fs.ensureDir(dirname(...)) before retrying. If the parent directory was deleted between the read and write steps (TOCTOU), the write failed with an unhandled ENOENT.

This PR extracts the write expression into a write const and adds the same Effect.catchReason("PlatformError", "NotFound", ...) + ensureDir + retry pattern already used by create (line 130-133).

How did you verify your code works?

  • bun turbo typecheck: all 29 packages pass
  • The catch pattern is identical to create — only fires on NotFound, normal path unaffected

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

writeIfUnchanged wrote without ensuring the parent directory exists,
unlike create which catches NotFound and calls ensureDir before retry.
If the parent dir is deleted between read and write, the write failed
with an unhandled ENOENT. Now matches create's catch+ensureDir+retry pattern.

Closes anomalyco#33075
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Edit tool writeIfUnchanged does not ensure parent directory exists before writing

2 participants