Skip to content

Commit

Permalink
Add test and fix exists behaviour for relative symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
timvahlbrock committed Feb 5, 2025
1 parent d3c8959 commit 9afed42
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 9afed42

Please sign in to comment.