Merge pull request #268 from humphd/issue267

Fix #267, readdir on file path should error
This commit is contained in:
Alan K 2014-08-20 15:56:22 -04:00
commit cf2469f270
3 changed files with 25 additions and 0 deletions

View File

@ -1085,6 +1085,8 @@ function read_directory(context, path, callback) {
function read_directory_data(error, result) {
if(error) {
callback(error);
} else if(result.mode !== MODE_DIRECTORY) {
callback(new Errors.ENOTDIR(null, path));
} else {
directoryNode = result;
context.getObject(directoryNode.data, handle_directory_data);

22
tests/bugs/issue267.js Normal file
View File

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

View File

@ -73,3 +73,4 @@ require("./bugs/ls-depth-bug");
require("./bugs/issue247.js");
require("./bugs/issue254.js");
require("./bugs/issue258.js");
require("./bugs/issue267.js");