Skip to content

Respect overwrite options when copying symlinks - #1084

Open
jakezwang wants to merge 1 commit into
jprichardson:masterfrom
jakezwang:fix-symlink-copy-overwrite
Open

jakezwang wants to merge 1 commit into
jprichardson:masterfrom
jakezwang:fix-symlink-copy-overwrite

Conversation

@jakezwang

Copy link
Copy Markdown

Copying a symlink currently replaces an existing destination symlink even with overwrite: false or clobber: false. It also succeeds with overwrite: false, errorOnExist: true instead of reporting the existing destination.

Apply the existing overwrite checks in the symlink branches of copy and copySync, before unlinking the destination. Tests cover valid and broken destination links, both overwrite options, errorOnExist, default replacement and missing destinations.

The new tests reproduce 12 failures before the fix. npm test passes on Node 20.20.2, 22.23.2 and 24.4.1: lint, 755 unit tests and ESM tests. Eight existing tests remain pending on macOS; cross-device and other platform tests were not run locally.

@RyanZim

RyanZim commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Of note, fs.cp() has the same behavior, and we would like to stay in sync with that: #912 (comment). So this should be potentially raised with Node itself.

@jakezwang

Copy link
Copy Markdown
Author

Understood. This was independently found edge-case behavior rather than a production incident. I have not opened an issue in Node, and I have not changed the proposed behavior further. Keeping fs-extra aligned with fs.cp() is a design constraint; this needs an upstream decision before treating the PR as ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants