Skip to content

fs: skip cp fast path when a vfs is mounted - #67893

Open
hamzakargin wants to merge 1 commit into
nodejs:mainfrom
hamzakargin:vfs-cp
Open

hamzakargin wants to merge 1 commit into
nodejs:mainfrom
hamzakargin:vfs-cp

Conversation

@hamzakargin

Copy link
Copy Markdown
Contributor

The fast path from #65488 sends a directory copy to native code, which cannot see paths inside a VFS mount, so fs.cp() and fs.promises.cp() of a directory fail there with ENOTDIR. This PR skips the fast path while a VFS is mounted (vfsState.handlers !== null). Real disk users keep the fast path, and VFS users use the JS walk.

Fixes: #67892

Testing: the new test/parallel/test-vfs-fs-cp.js copies a directory on VFS with fs.promises.cp() and fs.cp(), and checks that a real directory still copies while a VFS is mounted. It fails without the fix and passes with it. All test-fs-cp* and test-vfs* tests pass locally (222 tests, macOS arm64), and ESLint is clean.

AI disclosure: I used AI coding agents to help investigate the bug and write the fix and the test. I reviewed the change, reproduced the bug on main, and checked the test results above.

The native directory copy added in 29667e0 cannot see paths
inside a node:vfs mount, so fs.cp() and fs.promises.cp() of a
directory failed there with ENOTDIR. Use the JavaScript walk while
a virtual file system is mounted.

Fixes: nodejs#67892
Refs: nodejs#65488
Assisted-by: AI coding agents
Signed-off-by: Hamza Kargın <hamzakargin@outlook.com>
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Nov 30, 2026
@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.59%. Comparing base (1611823) to head (dcc831c).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67893      +/-   ##
==========================================
+ Coverage   90.58%   90.59%   +0.01%     
==========================================
  Files         802      802              
  Lines      286656   286662       +6     
  Branches    55369    55381      +12     
==========================================
+ Hits       259668   259708      +40     
+ Misses      17089    17064      -25     
+ Partials     9899     9890       -9     
Files with missing lines Coverage Δ
lib/internal/fs/cp/cp.js 93.19% <100.00%> (+0.04%) ⬆️

... and 39 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

2 participants