Merge pull request #242 from humphd/ls-depth-bug
sh.ls() fails when stack sized is reached for deep recursive listings
This commit is contained in:
commit
ef4de22586
|
@ -1,5 +1,7 @@
|
|||
var FILE_SYSTEM_NAME = require('../constants.js').FILE_SYSTEM_NAME;
|
||||
var asyncCallback = require('../../lib/async.js').nextTick;
|
||||
// NOTE: prefer setImmediate to nextTick for proper recursion yielding.
|
||||
// see https://github.com/js-platform/filer/pull/24
|
||||
var asyncCallback = require('../../lib/async.js').setImmediate;
|
||||
|
||||
/**
|
||||
* Make shared in-memory DBs possible when using the same name.
|
||||
|
|
|
@ -255,7 +255,7 @@ Shell.prototype.ls = function(dir, options, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
async.each(entries, getDirEntry, function(error) {
|
||||
async.eachSeries(entries, getDirEntry, function(error) {
|
||||
callback(error, result);
|
||||
});
|
||||
});
|
||||
|
@ -323,7 +323,7 @@ Shell.prototype.rm = function(path, options, callback) {
|
|||
// Root dir entries absolutely
|
||||
return Path.join(pathname, filename);
|
||||
});
|
||||
async.each(entries, remove, function(error) {
|
||||
async.eachSeries(entries, remove, function(error) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
var Filer = require('../..');
|
||||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
var async = require('../../lib/async.js');
|
||||
|
||||
describe('sh.ls and deep directory trees', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should not crash when calling sh.ls() on deep directory layouts', function(done) {
|
||||
var fs = util.fs();
|
||||
var sh = fs.Shell();
|
||||
|
||||
var path = '';
|
||||
for(var i=0; i<50; i++) {
|
||||
path += '/' + i;
|
||||
}
|
||||
|
||||
sh.mkdirp(path, function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
sh.ls('/', {recursive: true}, function(err, listing) {
|
||||
expect(err).not.to.exist;
|
||||
expect(listing).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not crash when calling sh.ls() on wide directory layouts', function(done) {
|
||||
var fs = util.fs();
|
||||
var sh = fs.Shell();
|
||||
|
||||
var dirName = '/dir';
|
||||
|
||||
fs.mkdir(dirName, function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
var paths = [];
|
||||
for(var i=0; i<100; i++) {
|
||||
paths.push(Filer.Path.join(dirName, ''+i));
|
||||
}
|
||||
|
||||
function writeFile(path, callback) {
|
||||
fs.writeFile(path, 'data', callback);
|
||||
}
|
||||
|
||||
async.eachSeries(paths, writeFile, function(err) {
|
||||
if(err) { console.log('error', err); throw err; }
|
||||
|
||||
sh.ls('/', {recursive: true}, function(err, listing) {
|
||||
expect(err).not.to.exist;
|
||||
expect(listing).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -68,3 +68,4 @@ require("./spec/node-js/simple/test-fs-watch-recursive");
|
|||
require("./bugs/issue105");
|
||||
require("./bugs/issue106");
|
||||
require("./bugs/issue239");
|
||||
require("./bugs/ls-depth-bug");
|
Loading…
Reference in New Issue