Merge pull request #335 from gideonthomas/issue334
Fix #334 - Do not allow fs.link on directories
This commit is contained in:
commit
841360de71
|
@ -942,6 +942,8 @@ function link_node(context, oldpath, newpath, callback) {
|
||||||
oldDirectoryData = result;
|
oldDirectoryData = result;
|
||||||
if(!_(oldDirectoryData).has(oldname)) {
|
if(!_(oldDirectoryData).has(oldname)) {
|
||||||
callback(new Errors.ENOENT('a component of either path prefix does not exist', 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 {
|
} else {
|
||||||
find_node(context, newParentPath, read_new_directory_data);
|
find_node(context, newParentPath, read_new_directory_data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue