Skip to content

fs: copy dangling symlinks over existing symlinks - #66948

Open
semimikoh wants to merge 1 commit into
nodejs:mainfrom
semimikoh:fix-fs-cp-dangling-symlink
Open

semimikoh wants to merge 1 commit into
nodejs:mainfrom
semimikoh:fix-fs-cp-dangling-symlink

Conversation

@semimikoh

@semimikoh semimikoh commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Use the existing source directory check instead of stat()ing the link target.

fs.cp() fails with ENOENT when a dangling source symlink replaces an existing symlink. This uses the already computed srcIsDir for the subdirectory check instead of calling stat(src), and adds a regression test.

The new regression test and the existing symlink protection test pass. The full test suite is still running.

Fixes: #66946

@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 Oct 23, 2026
@semimikoh
semimikoh force-pushed the fix-fs-cp-dangling-symlink branch 2 times, most recently from c3cd1c5 to 0b4bc15 Compare October 23, 2026 09:42
Reuse srcIsDir instead of stat() for the subdirectory check.

Signed-off-by: semimikoh <ejffjeosms@gmail.com>
@semimikoh
semimikoh force-pushed the fix-fs-cp-dangling-symlink branch from 0b4bc15 to e5b7ba7 Compare October 23, 2026 09:52
@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66948      +/-   ##
==========================================
- Coverage   90.60%   90.59%   -0.02%     
==========================================
  Files         797      797              
  Lines      278276   278325      +49     
  Branches    53498    53516      +18     
==========================================
+ Hits       252133   252139       +6     
- Misses      16506    16562      +56     
+ Partials     9637     9624      -13     
Files with missing lines Coverage Δ
lib/internal/fs/cp/cp.js 93.12% <100.00%> (-0.02%) ⬇️

... and 42 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.cp() fails to replace an existing symlink with a dangling symlink

2 participants