Skip to content

fix(io): honor no-overwrite when copying symlinks - #2588

Open
pradeep-ramola wants to merge 1 commit into
actions:mainfrom
pradeep-ramola:fix/io-symlink-no-clobber
Open

pradeep-ramola wants to merge 1 commit into
actions:mainfrom
pradeep-ramola:fix/io-symlink-no-clobber

Conversation

@pradeep-ramola

Copy link
Copy Markdown

Summary

Honor force: false when recursive cp() copies a symbolic link over an existing destination entry.

The symlink branch in copyFile currently unlinks the destination without checking force. For a recursive copy, an existing regular file can therefore be deleted and replaced with a symlink even though the caller explicitly disabled overwriting. Existing symlinks, including dangling ones, are replaced too.

Check force after the existing lstat succeeds and before unlinking. Using lstat here preserves dangling destination links as well as valid ones. The overwrite-enabled and missing-destination paths retain their existing behavior.

Regression coverage

Six filesystem cases cover regular files, valid symlinks, and dangling symlinks with force both enabled and disabled. They check preserved file contents or link targets, successful replacement when forced, and preservation of the original link target's contents. On Windows the tests use the existing junction helper, so they do not require elevated symlink permissions.

Before the production change, all three force: false cases failed and the three force: true controls passed.

Validation

  • npm test -- --runInBand packages/io/__tests__ (62 tests passed)
  • npm run tsc --prefix packages/io
  • npx eslint packages/io/src/io.ts packages/io/__tests__/io.test.ts
  • npx prettier --check packages/io/src/io.ts packages/io/__tests__/io.test.ts
  • git diff --check

Validated locally on Windows. AI assistance was used to develop and validate this change.

@pradeep-ramola
pradeep-ramola requested a review from a team as a code owner November 22, 2026 21:37

This branch has not been deployed

No deployments
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.

1 participant