[ISSUE #6] initial 'path' may, in fact, be a file

This commit is contained in:
AJ ONeal 2012-01-15 19:21:11 -07:00
parent 2dd4eee860
commit f1c2c4d5e1
1 changed files with 39 additions and 23 deletions

View File

@ -17,7 +17,9 @@
var emitter = new EventEmitter() var emitter = new EventEmitter()
, q = [] , q = []
, queue = [q] , queue = [q]
, curpath; , curpath
, firstRun = true
;
function readdirHandler(err, files) { function readdirHandler(err, files) {
var fnodeGroups = TypeEmitter.createNodeGroups(); var fnodeGroups = TypeEmitter.createNodeGroups();
@ -69,11 +71,7 @@
}); });
} }
if (err) { function readFiles() {
emitter.emit('directoryError', curpath, { error: err }, noop);
//emitter.emit('error', curpath, { error: err });
}
if (!files || 0 == files.length) { if (!files || 0 == files.length) {
return next(); return next();
} }
@ -92,6 +90,28 @@
} }
} }
if (err) {
if (!firstRun) {
emitter.emit('directoryError', curpath, { error: err }, noop);
readFiles();
return;
}
firstRun = false;
fs.lstat(curpath, function (e, stat) {
if (stat) {
files = [curpath.replace(/.*\//, '')];
curpath = curpath.replace(files[0], '');
}
readFiles();
})
//emitter.emit('error', curpath, { error: err });
return;
}
readFiles();
}
function walkSync() { function walkSync() {
var err, files; var err, files;
@ -105,11 +125,6 @@
} }
function walk() { function walk() {
if (sync) {
walkSync();
return;
}
fs.readdir(curpath, readdirHandler); fs.readdir(curpath, readdirHandler);
} }
@ -132,6 +147,7 @@
curpath = pathname; curpath = pathname;
if (sync) { if (sync) {
walk = walkSync;
process.nextTick(walk); process.nextTick(walk);
} else { } else {
walk(); walk();