Merge pull request #268 from humphd/issue267
Fix #267, readdir on file path should error
This commit is contained in:
commit
cf2469f270
|
@ -1085,6 +1085,8 @@ function read_directory(context, path, callback) {
|
||||||
function read_directory_data(error, result) {
|
function read_directory_data(error, result) {
|
||||||
if(error) {
|
if(error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
|
} else if(result.mode !== MODE_DIRECTORY) {
|
||||||
|
callback(new Errors.ENOTDIR(null, path));
|
||||||
} else {
|
} else {
|
||||||
directoryNode = result;
|
directoryNode = result;
|
||||||
context.getObject(directoryNode.data, handle_directory_data);
|
context.getObject(directoryNode.data, handle_directory_data);
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
var Filer = require('../..');
|
||||||
|
var util = require('../lib/test-utils.js');
|
||||||
|
var expect = require('chai').expect;
|
||||||
|
|
||||||
|
describe('fs.readdir on non-dir paths, issue 267', function() {
|
||||||
|
beforeEach(util.setup);
|
||||||
|
afterEach(util.cleanup);
|
||||||
|
|
||||||
|
it('should fail with ENOTDIR when called on filepath', function(done) {
|
||||||
|
var fs = util.fs();
|
||||||
|
|
||||||
|
fs.writeFile('/myfile.txt', 'data', function(err) {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
fs.readdir('/myfile.txt', function(err, contents) {
|
||||||
|
expect(err).to.exist;
|
||||||
|
expect(err.code).to.equal('ENOTDIR');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -73,3 +73,4 @@ require("./bugs/ls-depth-bug");
|
||||||
require("./bugs/issue247.js");
|
require("./bugs/issue247.js");
|
||||||
require("./bugs/issue254.js");
|
require("./bugs/issue254.js");
|
||||||
require("./bugs/issue258.js");
|
require("./bugs/issue258.js");
|
||||||
|
require("./bugs/issue267.js");
|
||||||
|
|
Loading…
Reference in New Issue