diff --git a/lib/package.json b/lib/package.json index b470d2c..54b00c2 100644 --- a/lib/package.json +++ b/lib/package.json @@ -10,5 +10,5 @@ }, "lib" : ".", "main" : "./walk.js", - "version" : "2.1.0" + "version" : "2.1.1" } diff --git a/lib/walk.js b/lib/walk.js index 9ee9927..81d4412 100644 --- a/lib/walk.js +++ b/lib/walk.js @@ -22,16 +22,17 @@ ; function readdirHandler(err, files) { - var fnodeGroups = TypeEmitter.createNodeGroups(); + var fnodeGroups = TypeEmitter.createNodeGroups() + ; function filesHandler(cont, file) { - var statPath; - - emitter.emit('name', curpath, file, noop); + var statPath + ; function lstatHandler(err, stat) { stat = stat || {}; stat.name = file; + if (err) { stat.error = err; //emitter.emit('error', curpath, stat); @@ -44,7 +45,10 @@ } } + emitter.emit('name', curpath, file, noop); + statPath = curpath + '/' + file; + if (sync) { try { lstatHandler(null, fs.lstatSync(statPath)); @@ -90,26 +94,27 @@ } } - 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 }); + if (!err) { + readFiles(); return; } - readFiles(); + 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(); + }); } function walkSync() {