Skip to content

fs: fix cpSync() abort when dest is a dangling symlink - #67142

Open
yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:fs-cpsync-dangling-dest
Open

yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:fs-cpsync-dangling-dest

Conversation

@yohannesjoya

Copy link
Copy Markdown

fs.cpSync() aborted the process (exit code 134) when the destination is a dangling symlink. CpSyncCheckPaths() called the throwing overload of std::filesystem::equivalent(), and the uncaught C++ exception bypassed JavaScript's try/catch. It now uses the std::error_code overload, as the parent-directory check further down already does. A dangling destination is not the same file as the source, so the copy goes ahead and replaces the link, matching v24 and fs.promises.cp().

Fixes: #67141

The new test aborts on main and passes with this change. tools/test.py parallel/test-fs-cp-* (91 tests), cpplint and make lint-js pass locally.

Not changed here: copying a symlink onto a dangling symlink with cpSync() still throws a catchable ENOENT from statSync(dest) in onLink(), as on v24. I can follow up on that separately.

AI disclosure: I used a coding agent to help locate the cause and draft the test. I reproduced the crash on v25.9.0, v26.13.0 and main, compared it with v24.22.2, reviewed the change line by line, and ran the tests above locally.

CpSyncCheckPaths() used the throwing overload of
std::filesystem::equivalent(), which fails when dest is a dangling
symlink. The uncaught C++ exception aborted the process. Use the
std::error_code overload instead: a dangling dest is not the same file
as src, so the copy goes ahead and replaces the link.

Fixes: nodejs#67141
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 Oct 30, 2026
@github-actions

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.

fs.cpSync() aborts the process when the destination is a dangling symlink

2 participants