Skip to content

Commit

Permalink
Merge pull request #195 from vlindhol/bug/symlink
Browse files Browse the repository at this point in the history
Binding.open not following symlinks correctly
  • Loading branch information
tschaub authored Feb 25, 2017
2 parents 84523af + b417c15 commit 05141ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Binding.prototype.open = function(pathname, flags, mode, callback) {
return maybeCallback(callback, this, function() {
var descriptor = new FileDescriptor(flags);
var item = this._system.getItem(pathname);
if (item instanceof SymbolicLink) {
while (item instanceof SymbolicLink) {
item = this._system.getItem(
path.resolve(path.dirname(pathname), item.getPath()));
}
Expand Down
9 changes: 9 additions & 0 deletions test/lib/binding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,15 @@ describe('Binding', function() {
assert.equal(String(buffer), 'one content');
});

it('reads from a deeply linked symlink', function() {
var binding = new Binding(system);
var fd = binding.open(path.join('mock-dir', 'one-link2.txt'), flags('r'));
var buffer = new Buffer(11);
var read = binding.read(fd, buffer, 0, 11, 0);
assert.equal(read, 11);
assert.equal(String(buffer), 'one content');
});

it('throws if not open for reading', function() {
var binding = new Binding(system);
var fd = binding.open(path.join('mock-dir', 'two.txt'), flags('w'));
Expand Down

0 comments on commit 05141ee

Please sign in to comment.