Repository navigation
fs: fix cpSync() abort when dest is a dangling symlink - #67142
Open
yohannesjoya wants to merge 1 commit into
Open
yohannesjoya wants to merge 1 commit into
yohannesjoya wants to merge 1 commit into
Conversation
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>
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. |
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.
fs.cpSync()aborted the process (exit code 134) when the destination is a dangling symlink.CpSyncCheckPaths()called the throwing overload ofstd::filesystem::equivalent(), and the uncaught C++ exception bypassed JavaScript'stry/catch. It now uses thestd::error_codeoverload, 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 andfs.promises.cp().Fixes: #67141
The new test aborts on main and passes with this change.
tools/test.py parallel/test-fs-cp-*(91 tests),cpplintandmake lint-jspass locally.Not changed here: copying a symlink onto a dangling symlink with
cpSync()still throws a catchableENOENTfromstatSync(dest)inonLink(), 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.