Skip to content

fix: fall back to copy+unlink when rename fails with EXDEV - #1

Open
dyk1454683243-sudo wants to merge 1 commit into
mainfrom
cursor/exdev-rename-fallback-240d
Open

dyk1454683243-sudo wants to merge 1 commit into
mainfrom
cursor/exdev-rename-fallback-240d

Conversation

@dyk1454683243-sudo

@dyk1454683243-sudo dyk1454683243-sudo commented Sep 20, 2026

Copy link
Copy Markdown
Owner

This fork-only PR was opened by the agent workflow. It is not the review target.

The upstream pull request is npm#241

Open in Web Open in Cursor 

When fs.rename fails with EXDEV (Windows AppX virtualized paths, or a
true cross-device move), write the temp file with copy+unlink so
writeFile / writeFileSync can still succeed. Rename remains the default
atomic path. Other rename errors are unchanged.

Fixes npm#71

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
@dyk1454683243-sudo
dyk1454683243-sudo marked this pull request as ready for review September 20, 2026 18:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 20, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-20T18:29:07.942390Z 70f6ca9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 70f6ca9316

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/index.js
if (!isExdevError(err)) {
throw err
}
await promisify(fs.copyFile)(tmpfile, dest)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fsync the copied destination before reporting success

When rename returns EXDEV and fsync is enabled, only the temporary source has been synced; copyFile creates dirty data in the destination, after which the source is unlinked and the operation reports success. A crash immediately after this fallback can therefore lose or truncate a write that the default fsync path would have persisted. The synchronous fallback has the same issue and should also sync the destination after copying.

Useful? React with 👍 / 👎.

Comment thread lib/index.js
if (!isExdevError(err)) {
throw err
}
await promisify(fs.copyFile)(tmpfile, dest)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid modifying the existing destination inode

On filesystems where copyFile overwrites an existing destination in place, the EXDEV fallback changes normal replacement semantics: if the destination has another hard link, that other pathname is also rewritten, whereas the original rename path replaces only the requested directory entry and leaves the other link's contents intact. The synchronous copyFileSync path behaves similarly, so this fallback should copy to a destination-side temporary file and replace the destination rather than copying directly over it.

Useful? React with 👍 / 👎.

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.

2 participants