Merge pull request #335 from gideonthomas/issue334

Fix #334 - Do not allow fs.link on directories
This commit is contained in:
Alan K 2014-12-17 14:22:40 -05:00
commit 841360de71
2 changed files with 16 additions and 0 deletions

View File

@ -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);
}

View File

@ -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();
});
});
});
});