Fix #288 - fs.unlink should fail on directory nodes
This commit is contained in:
parent
ed60c0b1fb
commit
19eea4f502
|
@ -1040,6 +1040,16 @@ function unlink_node(context, path, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
function check_if_node_is_directory(error, result) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
} else if(result.mode === 'DIRECTORY') {
|
||||
callback(new Errors.EISDIR('unlink not permitted on directories', name));
|
||||
} else {
|
||||
update_file_node(null, result);
|
||||
}
|
||||
}
|
||||
|
||||
function check_if_file_exists(error, result) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
|
@ -1048,7 +1058,7 @@ function unlink_node(context, path, callback) {
|
|||
if(!_(directoryData).has(name)) {
|
||||
callback(new Errors.ENOENT('a component of the path does not name an existing file', name));
|
||||
} else {
|
||||
context.getObject(directoryData[name].id, update_file_node);
|
||||
context.getObject(directoryData[name].id, check_if_node_is_directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,4 +82,24 @@ describe('fs.unlink', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not unlink directories', function (done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.mkdir('/mydir', function (error) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.unlink('/mydir', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EISDIR');
|
||||
|
||||
fs.stat('/mydir', function (error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats).to.exist;
|
||||
expect(stats.type).to.equal('DIRECTORY');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue