diff --git a/lib/walk.js b/lib/walk.js index abd2579..f4a9b6c 100644 --- a/lib/walk.js +++ b/lib/walk.js @@ -77,6 +77,7 @@ if (err) { stat.error = err; //me.emit('error', curpath, stat); + // TODO v3.0 (don't noop the next if there are listeners) me.emit('nodeError', me._wcurpath, stat, noop); me._wfnodegroups.errors.push(stat); me._wCurFileCallback(); @@ -127,6 +128,8 @@ ; if (me._wfnodegroups.errors.length) { + // TODO v3.0 (don't noop the next) + // .errors is an array of stats with { name: name, error: error } me.emit('errors', me._wcurpath, me._wfnodegroups.errors, noop); } // XXX emitNodeTypes still needs refactor @@ -154,6 +157,8 @@ Walker.prototype._wReaddirHandler = function (err, files) { var fnodeGroups = TypeEmitter.createNodeGroups() , me = this + , parent + , child ; me._wfnodegroups = fnodeGroups; @@ -165,9 +170,15 @@ return; } + // TODO path.sep + me._wcurpath = me._wcurpath.replace(/\/$/, ''); + // error? not first run? => directory error if (!me._wfirstrun) { + // TODO v3.0 (don't noop the next if there are listeners) me.emit('directoryError', me._wcurpath, { error: err }, noop); + // TODO v3.0 + //me.emit('directoryError', me._wcurpath.replace(/^(.*)\/.*$/, '$1'), { name: me._wcurpath.replace(/^.*\/(.*)/, '$1'), error: err }, noop); me._wReadFiles(); return; } @@ -175,15 +186,22 @@ // error? first run? => maybe a file, maybe a true error me._wfirstrun = false; - // readdir failed, try stat (might be a file) - me._wcurpath = me._wcurpath.replace(/^.*\/$/, ''); - fs[me._wStat](me._wcurpath, function (e, stat) { + // readdir failed (might be a file), try a stat on the parent + parent = me._wcurpath.replace(/^(.*)\/.*$/, '$1'); + fs[me._wStat](parent, function (e, stat) { if (stat) { - files = [me._wcurpath]; - me._wcurpath = me._wcurpath.replace(files[0], ''); + // success + // now try stat on this as a child of the parent directory + child = me._wcurpath.replace(/^.*\/(.*)$/, '$1'); + files = [child]; + me._wcurpath = parent; } else { - me.emit('nodeError', me._wcurpath, { error: e }, noop); + // TODO v3.0 + //me.emit('directoryError', me._wcurpath.replace(/^(.*)\/.*$/, '$1'), { name: me._wcurpath.replace(/^.*\/(.*)/, '$1'), error: err }, noop); + // TODO v3.0 (don't noop the next) + // the original readdir error, not the parent stat error + me.emit('nodeError', me._wcurpath, { error: err }, noop); } me._wReadFiles(); diff --git a/package.json b/package.json index 165a20d..d19fc16 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "lib": ".", "main": "./lib/walk.js", - "version": "2.3.7", + "version": "2.3.8", "repository": { "url": "git://github.com/coolaj86/node-walk.git" },