Open jandockx opened 5 months ago
Good catch, that's definitely a bug.
BTW, I appreciate your clearly-written issue; it has all the information I need, and none of the information I don't. It's a breath of fresh air; if everyone filed issues like this, my job as an open-source maintainer would be much easier. Just thought it's worthy of a shout-out.
Looks like createSymlinkSync
has the same bug as well: https://github.com/jprichardson/node-fs-extra/blob/426bb46067a57deacb93259d5af8b20d8ab528c0/lib/ensure/symlink.js#L58-L67
It seems like the simplest fix would be to stat
both the srcpath
& the srcpath
relative to the dst, with proper error handling (as we expect at least one of the calls to fail), then check which one actually returned stats, and run it through the areIdentical
check.
If you want to take a stab at a PR, that'd be welcome; otherwise, I'll try to get to this myself in the coming week or two.
Glad to be of service.
I will not be taking a stab at a PR at this time. I'm trying to make progress on my own thing (https://bitbucket.org/toryt/git-backup) during my holiday, where fs-extra
has been a great help so far just getting some things done. Thanks. This was just the first time I started playing with symbolic links.
I've worked around the issue for now, so, as far as I’m concerned, take your time. fs-extra
has been a tremendous help in personal and professional projects for years already, so thank you again.
Just be sure not to include any backdoors in here :-).
fs-extra
version: 11.2.0Issue
This works if the reference to the
target
is an absolute path, but fails if the reference is a relative path.Example
This is a
mocha
test that shows the issue. The first test ensures the symbolic link a second time with an absolute path, which succeeds as expected. The second test ensures the symbolic link a second time with a relative path, which is rejected withENOENT
, but should succeed too.Analysis
The issue is clear in
fs-extra/lib/ensure/symlink.js
, line 24, versus line 32.When there is no symbolic link yet at
dstpath
, theif
of line 22 is skippedand we arrive at line 31—32 where work is done to deal with relative
srcpath
s:When there is a symbolic link at
dstpath
, theif
–branch at line 22 is executed. Here, the status of thesrcpath
is requested as is:This evaluates a relative
srcpath
relative to thecwd
, not to thedstpath
. At that location the source does not exist, which results inENOENT
.