Skip to content

Commit

Permalink
[FIXES #2096] fix relative symlinks of symlinks (#2454)
Browse files Browse the repository at this point in the history
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:

```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 #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.
  • Loading branch information
stefanpenner authored and bestander committed Jan 20, 2017
1 parent edd1a07 commit 65e89b5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export async function symlink(src: string, dest: string): Promise<void> {
await fsSymlink(src, dest, 'junction');
} else {
// use relative paths otherwise which will be retained if the directory is moved
const relative = path.relative(path.dirname(dest), src);
const relative = path.relative(fs.realpathSync(path.dirname(dest)), fs.realpathSync(src));
await fsSymlink(relative, dest);
}
} catch (err) {
Expand Down

0 comments on commit 65e89b5

Please sign in to comment.