From 0fc2b585cfb88c977875a28e35706d1b2225aa48 Mon Sep 17 00:00:00 2001 From: Ville Lindholm Date: Sat, 25 Feb 2017 13:59:01 +0200 Subject: [PATCH 1/2] Bugfix opening a deeply symlinked file --- lib/binding.js | 2 +- test/lib/binding.spec.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/binding.js b/lib/binding.js index 39d054b7..baa885d2 100644 --- a/lib/binding.js +++ b/lib/binding.js @@ -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())); } diff --git a/test/lib/binding.spec.js b/test/lib/binding.spec.js index 98b1828c..33226490 100644 --- a/test/lib/binding.spec.js +++ b/test/lib/binding.spec.js @@ -763,7 +763,6 @@ describe('Binding', function() { parseInt('0666', 8)); }); }); - }); describe('#close()', function() { @@ -824,6 +823,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')); From b417c15dc2ea00dea9d3d4061fb4655e059df02a Mon Sep 17 00:00:00 2001 From: Ville Lindholm Date: Sat, 25 Feb 2017 14:01:51 +0200 Subject: [PATCH 2/2] whitespace --- test/lib/binding.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lib/binding.spec.js b/test/lib/binding.spec.js index 33226490..4719e34a 100644 --- a/test/lib/binding.spec.js +++ b/test/lib/binding.spec.js @@ -763,6 +763,7 @@ describe('Binding', function() { parseInt('0666', 8)); }); }); + }); describe('#close()', function() {