fix(ensureSymlink): resolve relative srcpath correctly when symlink exists#1064
Merged
RyanZim merged 1 commit intojprichardson:masterfrom Feb 26, 2026
Merged
Conversation
…xists When ensureSymlink is called with a relative srcpath and the destination symlink already exists, the code was incorrectly resolving the srcpath relative to cwd instead of relative to the dstpath directory. This caused ENOENT errors when calling ensureSymlink a second time with the same relative path, because fs.stat() evaluated the relative path from the wrong location. The fix checks if srcpath is relative, and if so, first tries to resolve it relative to dstpath's directory (standard symlink behavior), falling back to cwd if that doesn't exist. Fixes jprichardson#1038 Co-Authored-By: Claude Opus 4.6 <[email protected]>
RyanZim
approved these changes
Feb 26, 2026
Collaborator
RyanZim
left a comment
There was a problem hiding this comment.
Verified added tests as failing before changes.
LGTM
Collaborator
|
Probably won't get this released until next week, though. |
Collaborator
|
Released in |
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.
Summary
Fixes #1038
When
ensureSymlinkis called with a relativesrcpathand the destination symlink already exists, the code was incorrectly resolving thesrcpathrelative tocwdinstead of relative to thedstpathdirectory.This caused
ENOENTerrors when callingensureSymlinka second time with the same relative path:Root Cause
In
symlink.jslines 22-28 (async) and 48-52 (sync), when checking if an existing symlink already points to the correct target,fs.stat(srcpath)was called directly. For relative paths, this evaluates fromcwd, not from the symlink's directory.Fix
When
srcpathis relative, first try to resolve it relative todstpath's directory (standard symlink behavior), falling back tocwdif that doesn't exist. This mirrors the logic already used insymlinkPaths().Changes
lib/ensure/symlink.js: Fix relative path resolution in bothcreateSymlinkandcreateSymlinkSynclib/ensure/__tests__/symlink.test.js: Add regression tests for issuecreateSymlinkfails when ensuring a symbolic link with a relative path if the link already exists #1038Test Plan
createSymlinkfails when ensuring a symbolic link with a relative path if the link already exists #1038🤖 Generated with Claude Code