Skip to content

fs: handle cpSync copyDir filesystem errors#63971

Open
ChrisChan0668 wants to merge 1 commit into
nodejs:mainfrom
ChrisChan0668:fix-fs-cpsync-copydir-errors
Open

fs: handle cpSync copyDir filesystem errors#63971
ChrisChan0668 wants to merge 1 commit into
nodejs:mainfrom
ChrisChan0668:fix-fs-cpsync-copydir-errors

Conversation

@ChrisChan0668

Copy link
Copy Markdown

The native fs.cpSync() copyDir fast path is used for recursive copies when no filter option is provided. Some std::filesystem calls in that path used throwing overloads instead of overloads that report failures through std::error_code.

When directory iteration, path canonicalization, or file type checks failed, those C++ exceptions could bypass Node's normal error conversion. Instead of reporting a JavaScript exception that callers can catch, the process could terminate in the native layer.

Use non-throwing std::filesystem overloads throughout the copyDir implementation and convert each failure with ThrowStdErrException. Also add a Windows regression test that denies access to a copied directory and verifies cpSync throws in the child process instead of aborting.

Fixes: #63970

The native fs.cpSync() copyDir fast path is used for recursive
copies when no filter option is provided. Some std::filesystem
calls in that path used throwing overloads instead of overloads
that report failures through std::error_code.

When directory iteration, path canonicalization, or file type
checks failed, those C++ exceptions could bypass Node's normal
error conversion. Instead of reporting a JavaScript exception
that callers can catch, the process could terminate in the
native layer.

Use non-throwing std::filesystem overloads throughout the copyDir
implementation and convert each failure with ThrowStdErrException.
Also add a Windows regression test that denies access to a copied
directory and verifies cpSync throws in the child process instead
of aborting.

Fixes: nodejs#63970
Signed-off-by: ChrisChan0668 <192564531+ChrisChan0668@users.noreply.github.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 the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jun 18, 2026
@ChrisChan0668

Copy link
Copy Markdown
Author

Tests run locally on Windows:

  • vcbuild.bat release x64 openssl-no-asm no-cctest with config_flags=--v8-disable-temporal-support
  • python tools\test.py --mode=release parallel\test-fs-cp-sync-inaccessible-dir-error
  • git diff HEAD~1..HEAD --check
  • python tools\cpplint.py src\node_file.cc
  • node tools\eslint\node_modules\eslint\bin\eslint.js --cache --max-warnings=0 --report-unused-disable-directives --rule "@stylistic/js/linebreak-style: 0" test\parallel\test-fs-cp-sync-inaccessible-dir-error.mjs

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 the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs: cpSync copyDir fast path can terminate on filesystem errors

2 participants