Skip to content

fs: copy dangling symlinks over existing symlinks - #66948

Open
semimikoh wants to merge 2 commits into
nodejs:mainfrom
semimikoh:fix-fs-cp-dangling-symlink
Open

semimikoh wants to merge 2 commits 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 3 times, most recently 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.69%. Comparing base (768315c) to head (ff568e2).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66948      +/-   ##
==========================================
- Coverage   90.69%   90.69%   -0.01%     
==========================================
  Files         797      797              
  Lines      279572   279571       -1     
  Branches    53778    53776       -2     
==========================================
- Hits       253569   253558      -11     
- Misses      16287    16299      +12     
+ Partials     9716     9714       -2     
Files with missing lines Coverage Δ
lib/internal/fs/cp/cp.js 93.12% <100.00%> (-0.02%) ⬇️

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

Reuse srcIsDir instead of stat() for the subdirectory check.

Signed-off-by: semimikoh <ejffjeosms@gmail.com>
Signed-off-by: Semi Koh <ejffjeosms@gmail.com>
@semimikoh
semimikoh force-pushed the fix-fs-cp-dangling-symlink branch from e5b7ba7 to ff568e2 Compare November 9, 2026 06:21
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