Repository navigation
fs: fix cpSync() abort when dest is a dangling symlink - #67142
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>
|
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. |
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67142 +/- ##
==========================================
- Coverage 90.67% 90.67% -0.01%
==========================================
Files 797 797
Lines 278806 278774 -32
Branches 53621 53609 -12
==========================================
- Hits 252813 252780 -33
- Misses 16341 16350 +9
+ Partials 9652 9644 -8
π New features to boost your workflow:
|
Failed to resume CI
Full Auto Start CI output |
|
This has two approvals and the last CI run (78886) is green. Could a collaborator add |
|
Landed in 19f2d8e |
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: #67141 Signed-off-by: yohannesjoya <yohannesdestagebru10@gmail.com> PR-URL: #67142 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
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: #67141 Signed-off-by: yohannesjoya <yohannesdestagebru10@gmail.com> PR-URL: #67142 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
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: #67141 Signed-off-by: yohannesjoya <yohannesdestagebru10@gmail.com> PR-URL: #67142 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
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> PR-URL: nodejs#67142 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
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.