Skip to content

Commit

Permalink
Merge pull request #415 from timvahlbrock/fix/exists-symlink
Browse files Browse the repository at this point in the history
Add test and fix exists behaviour for relative symlinks
  • Loading branch information
tschaub authored Feb 6, 2025
2 parents d3c8959 + 9afed42 commit 88e9f00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,11 @@ Binding.prototype.exists = function (filepath, callback, ctx) {

if (item) {
if (item instanceof SymbolicLink) {
return this.exists(item.getPath(), callback, ctx);
return this.exists(
path.resolve(path.dirname(filepath), item.getPath()),
callback,
ctx,
);
}
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions test/lib/fs.link-symlink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,10 @@ describe('fs.symlinkSync(srcpath, dstpath, [type])', function () {
fs.symlinkSync('dir', 'link');
assert.isTrue(fs.statSync('link').isDirectory());
});

it('exists works if symlink is relative', function () {
fs.renameSync('file.txt', 'dir/file.txt');
fs.symlinkSync('file.txt', 'dir/link.txt');
assert.isTrue(fs.existsSync('dir/link.txt'));
});
});

0 comments on commit 88e9f00

Please sign in to comment.