Skip to content

fs: stat src through symlinks in cpSync() when dereference is set - #67340

Open
yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:fs-cpsync-dereference-src
Open

yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:fs-cpsync-dereference-src

Conversation

@yohannesjoya

Copy link
Copy Markdown

cpSync() checked src with symlink_status() when dereference was true and with status() when it was false, the reverse of what the option means. #59681 fixed the same swap for dest but left src as it was. So a symlink to a file passed as src with dereference: true was treated as a directory: cpSync() threw ERR_FS_EISDIR unless recursive was set, while fs.cp() copied the file.

This swaps the two calls and drops the check that counted a symlink as a directory, which status() can no longer return. The new test covers both cpSync() and fs.cp() and fails on main.

This is @npaun's fix from #60945, which the stale bot closed. I asked there on Oct 31 whether they planned to reopen it and got no reply, so I've rebased it and added the test, with them as co-author.

Refs: #59168

AI disclosure: I used an AI assistant to help find, test and write up this change. I reviewed and tested it myself.

CpSyncCheckPaths() used symlink_status() for src when dereference was
true and status() when it was false, the reverse of what the option
means. nodejs#59681 fixed the same swap for dest but left src as it was.
A symlink to a file passed as src with dereference: true was treated
as a directory, so cpSync() threw ERR_FS_EISDIR unless recursive was
set, while fs.cp() copied the file.

Swap the two calls and drop the check that counted a symlink as a
directory, which status() can no longer return.

Refs: nodejs#59168
Refs: nodejs#60945
Co-authored-by: Nicholas Paun <npaun@cloudflare.com>
Signed-off-by: yohannesjoya <yohannesdestagebru10@gmail.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants