Skip to content

Preserve existing ln destinations unless force is requested - #1288

Open
FanWu-ai wants to merge 1 commit into
shelljs:mainfrom
FanWu-ai:fix-ln-preserve-existing-destination-oct13
Open

FanWu-ai wants to merge 1 commit into
shelljs:mainfrom
FanWu-ai:fix-ln-preserve-existing-destination-oct13

Conversation

@FanWu-ai

Copy link
Copy Markdown

ln(source, existingDestination) reports Destination file exists but then continues to unlinkSync() and replaces the destination anyway. Without -f, this can overwrite a regular file, replace an existing symlink, or delete the source itself when source and destination are the same path.

Stop the command at the existing-destination error. The returned failure status/message and explicit -f/-sf behavior are preserved.

Tests strengthen the existing destination check and add nine cases covering regular files, symlink destinations, missing sources, self-links, fatal mode and a dangling-link control.

Validation on Linux / Node.js 24.19.0:

  • Fresh baseline: 640 passed / 6 existing skips, including post-test lint.
  • Final tests against unchanged production code: 8 fail because destinations are changed or removed; the two new controls pass. Final focused suite: 25 passed.
  • Complete npm test and coverage runs: 649 passed / 6 existing skips each.
  • Separate lint, check-node-support, generated-documentation consistency and git diff --check pass.
  • 16 additional GNU ln differential scenarios pass, including inode/content preservation and explicit force controls.

The six existing explicit skips are in cmd.js: five async cases and the missing-exec-path case. Native Windows/macOS and other Node versions were not run locally; symlink-setup cases use the project's existing Windows skip helper.

This addresses rejection of an existing destination without -f, separately from the forced dangling-symlink behavior in #1281 and directory-destination support in #833. No existing issue is claimed closed.

Prepared and tested with AI assistance (OpenAI Codex). No human review is claimed.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 12, 2026 21:54
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