joyent/node — pull request #8813 by vweevers (2014-12-03 14:48:14+00:00)
Title: Relative junction should behave like dangling symlink

A junction path must be absolute, which is why fs.symlink resolves paths on Windows if the type is `junction`. E.g. `fs.symlink("../foo", "my/link", "junction")`. From the [docs](http://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback):

> `fs.symlink(srcpath, dstpath, [type], callback)`
>
> Note that Windows junction points require the destination path to be absolute. When using 'junction', the destination argument will automatically be **normalized to absolute path**.

*Sidenote*: Reading that, you'd think the `dstpath` argument is normalized. What the docs mean to say is that the `srcpath` (the *target*) is normalized. The function signature in the source is `fs.symlink(destination, path)`; these inconsistencies are confusing.

However, the target seems to be normalized relative to the working directory - not relative to the link's parent directory like it should:

> `man ln`
>
> Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.

Of course, a junction is not the same as a symlink, but the behavior should be consistent, given that node on unix ignores the `junction` argument and will create a dangling symlink. It should do the same on Windows, or at least simulate it. This PR normalizes the target, relative to the link's parent directory. Meaning:

`fs.symlink("..\foo", "C:\my\link", "junction")`

becomes:

`fs.symlink("C:\foo", "C:\my\link", "junction")`

The included test is copied from `test-fs-symlink-dir-junction.js`. These tests could probably be merged, I didn't (yet) for the sake of clarity - and because the other (regular symlink) tests fail anyway on Windows XP.