fs: pass symlink type in cp when filter is provided#62654
Open
shulaoda wants to merge 2 commits intonodejs:mainfrom
Open
fs: pass symlink type in cp when filter is provided#62654shulaoda wants to merge 2 commits intonodejs:mainfrom
shulaoda wants to merge 2 commits intonodejs:mainfrom
Conversation
avivkeller
approved these changes
Apr 9, 2026
juanarbol
approved these changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
fs.cp/fs.cpSyncis called with bothverbatimSymlinks: trueand afilterfunction, directory symlinks are incorrectly created as file symlinks on Windows.Root cause
fs.cptakes two code paths:filter: the C++ fast path (cpSyncCopyDir) usesstd::filesystem::copy_symlink()which preserves the symlink type automatically.filter: the JS fallback path callssymlinkSync(resolvedSrc, dest)without atypeparameter. On Windows,symlinkSynctries to auto-detect the type by stat-ing the resolved target at the destination. During a recursive copy, the target directory may not yet exist at the destination (e.g.linked/is copied beforepackages/in alphabetical order), so stat fails andtypedefaults to'file'creating a file symlink instead of a directory symlink.Fix
Detect the symlink type from the source (which always exists) using
internalModuleStat(src)and pass it explicitly tosymlinkSync/symlink. TheonLinkfunction already computedsrcIsDirfor subdirectory validation but only after the early-return paths this change moves it before those returns and threads the derivedsymlinkTypethrough to allsymlinkSync/symlinkcall sites.Both the sync (
cp-sync.js) and async (cp.js) implementations are fixed.Test
Added two test files that verify directory symlinks are preserved when copying with
verbatimSymlinks: trueand afilterfunction:test-fs-cp-sync-verbatim-dir-symlinks-with-filter.mjstest-fs-cp-async-verbatim-dir-symlinks-with-filter.mjsFixes: #62653