diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 5bed6e5..20a8f52 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -942,6 +942,8 @@ function link_node(context, oldpath, newpath, callback) { oldDirectoryData = result; if(!_(oldDirectoryData).has(oldname)) { callback(new Errors.ENOENT('a component of either path prefix does not exist', oldname)); + } else if(oldDirectoryData[oldname].type === 'DIRECTORY') { + callback(new Errors.EPERM('oldpath refers to a directory')); } else { find_node(context, newParentPath, read_new_directory_data); } diff --git a/tests/spec/fs.link.spec.js b/tests/spec/fs.link.spec.js index c1c68d2..e1c8e1a 100644 --- a/tests/spec/fs.link.spec.js +++ b/tests/spec/fs.link.spec.js @@ -69,4 +69,18 @@ describe('fs.link', function() { }); }); }); + + it('should not allow links to a directory', function(done) { + var fs = util.fs(); + + fs.mkdir('/mydir', function(error) { + if(error) throw error; + + fs.link('/mydir', '/mydirlink', function(error) { + expect(error).to.exist; + expect(error.code).to.equal('EPERM'); + done(); + }); + }); + }); });