-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIXES #2096] fix relative symlinks of symlinks #2454
Conversation
This makes yarn link work when $HOME/.config/yarn/link/ is itself a symlink. ---- The following commit forces symlinks to be relative: yarnpkg@36d73cc This isn't ideal, although it enables some portability it breaks others. For example, it is not uncommon for `$HOME/.config` itself to be be a symlink: `$HOME/.config` -> `$HOME/src/stefanpenner/dotfiles`. Now when running `yarn link` inside `$HOME/src/ember-cli/ember-cli` we end up with: ```js path.relative('/Users/spenner/.config/yarn/link/ember-cli', '/Users/spenner/src/ember-cli/ember-cli'); => '../../../src/ember-cli/ember-cli' ``` Which results in the link located at: `/Users/spenner/.config/yarn/link/ember-cli` pointing to `/Users/spenner/.config/src/ember-cli/ember-cli` rather then `/Users/spenner/src/ember-cli/ember-cli` This is because `/Users/spenner/.config` is actually a symlink pointing to `/Users/spenner/src/stefanpenner/dotfiles/.config/` --- This PR provides mitigate the issue raised in yarnpkg#2096, but reifying the paths via `realpathSync` before deriving the relative path. This doesn't fix all issues, e.g. symlinks cannot be changed after this reification.
I've just stumbled upon this PR, but I don't understand it.
I don't understand this last sentence. If @stefanpenner Do you recall more details? This |
I don’t really recall. I believe my pr was simply the best of two evils. IMHO the entire endeavor of changing how fs symlink works is fraught with peril, and should be truely reconsidered |
Summary
This makes
yarn link
work when$HOME/.config/yarn/link/
is itself a symlink.The following commit forces symlinks to be relative: 36d73cc
This isn't ideal, although it enables some portability it breaks others. For example, it is not uncommon for
$HOME/.config
itself to be be a symlink:$HOME/.config
->$HOME/src/stefanpenner/dotfiles
.Now when running
yarn link
inside$HOME/src/ember-cli/ember-cli
we end up with:Which results in the link located at:
/Users/spenner/.config/yarn/link/ember-cli
pointing to/Users/spenner/.config/src/ember-cli/ember-cli
rather then/Users/spenner/src/ember-cli/ember-cli
This is because
/Users/spenner/.config
is actually a symlink pointing to/Users/spenner/src/stefanpenner/dotfiles/.config/
This PR mitigates he issue raised in #2096, but reifying the paths via
realpathSync
before deriving the relative path. This ensures that at the time of linking, the paths are correct. This doesn't fix all issues, e.g. symlinks cannot always be changed after this reification.Test plan
src/lib/fs.js
appears currently untested... if this is an approach you all would like to take I can add some tests.