Skip to content

Commit 920c4a9

Browse files
authored
Merge pull request #232 from deployable/issue_231_readlink_EINVAL
Throw ENOENT in readlink when item is missing
2 parents b6d9aee + b46797c commit 920c4a9

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

lib/binding.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,9 @@ Binding.prototype.readlink = function(pathname, encoding, callback) {
10351035
}
10361036
return maybeCallback(normalizeCallback(callback), this, function() {
10371037
var link = this._system.getItem(pathname);
1038+
if (!link) {
1039+
throw new FSError('ENOENT', pathname);
1040+
}
10381041
if (!(link instanceof SymbolicLink)) {
10391042
throw new FSError('EINVAL', pathname);
10401043
}

test/lib/binding.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,21 +1506,21 @@ describe('Binding', function() {
15061506
var binding = new Binding(system);
15071507
assert.throws(function() {
15081508
binding.readlink(path.join('mock-dir', 'one.txt'));
1509-
});
1509+
}, /EINVAL/);
15101510
});
15111511

15121512
it('fails for directories', function() {
15131513
var binding = new Binding(system);
15141514
assert.throws(function() {
15151515
binding.readlink(path.join('mock-dir', 'empty'));
1516-
});
1516+
}, /EINVAL/);
15171517
});
15181518

15191519
it('fails for bogus paths', function() {
15201520
var binding = new Binding(system);
15211521
assert.throws(function() {
15221522
binding.readlink(path.join('mock-dir', 'bogus'));
1523-
});
1523+
}, /ENOENT/);
15241524
});
15251525
});
15261526

0 commit comments

Comments
 (0)