Merge pull request #325 from gideonthomas/issue256
Fix #256 - fs.read() for dir paths should fail
This commit is contained in:
commit
b1cf2d7dfb
|
@ -813,6 +813,8 @@ function read_data(context, ofd, buffer, offset, length, position, callback) {
|
|||
function read_file_data(error, result) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
} else if(result.mode === 'DIRECTORY') {
|
||||
callback(new Errors.EISDIR('the named file is a directory', ofd.path));
|
||||
} else {
|
||||
fileNode = result;
|
||||
context.getBuffer(fileNode.data, handle_file_data);
|
||||
|
|
|
@ -61,4 +61,28 @@ describe('fs.read', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to read a directory', function(done) {
|
||||
var fs = util.fs();
|
||||
var buf = new Filer.Buffer(20);
|
||||
var buf2 = new Filer.Buffer(20);
|
||||
buf.fill(0);
|
||||
buf2.fill(0);
|
||||
|
||||
fs.mkdir('/mydir', function(error) {
|
||||
if(error) throw err;
|
||||
|
||||
fs.open('/mydir', 'r', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.read(fd, buf, 0, buf.length, 0, function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EISDIR');
|
||||
expect(result).to.equal(0);
|
||||
expect(buf).to.deep.equal(buf2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue