Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding.open not following symlinks correctly #195

Merged
merged 2 commits into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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