Skip to content

Commit 9afed42

Browse files
committed
Add test and fix exists behaviour for relative symlinks
1 parent d3c8959 commit 9afed42

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/binding.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,11 @@ Binding.prototype.exists = function (filepath, callback, ctx) {
14941494

14951495
if (item) {
14961496
if (item instanceof SymbolicLink) {
1497-
return this.exists(item.getPath(), callback, ctx);
1497+
return this.exists(
1498+
path.resolve(path.dirname(filepath), item.getPath()),
1499+
callback,
1500+
ctx,
1501+
);
14981502
}
14991503
return true;
15001504
}

test/lib/fs.link-symlink.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,10 @@ describe('fs.symlinkSync(srcpath, dstpath, [type])', function () {
309309
fs.symlinkSync('dir', 'link');
310310
assert.isTrue(fs.statSync('link').isDirectory());
311311
});
312+
313+
it('exists works if symlink is relative', function () {
314+
fs.renameSync('file.txt', 'dir/file.txt');
315+
fs.symlinkSync('file.txt', 'dir/link.txt');
316+
assert.isTrue(fs.existsSync('dir/link.txt'));
317+
});
312318
});

0 commit comments

Comments
 (0)