fixes to fixes

This commit is contained in:
AJ ONeal 2015-01-05 19:06:32 -07:00
parent 24d237ae74
commit a72cd5e478
2 changed files with 25 additions and 7 deletions

View File

@ -77,6 +77,7 @@
if (err) { if (err) {
stat.error = err; stat.error = err;
//me.emit('error', curpath, stat); //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.emit('nodeError', me._wcurpath, stat, noop);
me._wfnodegroups.errors.push(stat); me._wfnodegroups.errors.push(stat);
me._wCurFileCallback(); me._wCurFileCallback();
@ -127,6 +128,8 @@
; ;
if (me._wfnodegroups.errors.length) { 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); me.emit('errors', me._wcurpath, me._wfnodegroups.errors, noop);
} }
// XXX emitNodeTypes still needs refactor // XXX emitNodeTypes still needs refactor
@ -154,6 +157,8 @@
Walker.prototype._wReaddirHandler = function (err, files) { Walker.prototype._wReaddirHandler = function (err, files) {
var fnodeGroups = TypeEmitter.createNodeGroups() var fnodeGroups = TypeEmitter.createNodeGroups()
, me = this , me = this
, parent
, child
; ;
me._wfnodegroups = fnodeGroups; me._wfnodegroups = fnodeGroups;
@ -165,9 +170,15 @@
return; return;
} }
// TODO path.sep
me._wcurpath = me._wcurpath.replace(/\/$/, '');
// error? not first run? => directory error // error? not first run? => directory error
if (!me._wfirstrun) { if (!me._wfirstrun) {
// TODO v3.0 (don't noop the next if there are listeners)
me.emit('directoryError', me._wcurpath, { error: err }, noop); 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(); me._wReadFiles();
return; return;
} }
@ -175,15 +186,22 @@
// error? first run? => maybe a file, maybe a true error // error? first run? => maybe a file, maybe a true error
me._wfirstrun = false; me._wfirstrun = false;
// readdir failed, try stat (might be a file) // readdir failed (might be a file), try a stat on the parent
me._wcurpath = me._wcurpath.replace(/^.*\/$/, ''); parent = me._wcurpath.replace(/^(.*)\/.*$/, '$1');
fs[me._wStat](me._wcurpath, function (e, stat) { fs[me._wStat](parent, function (e, stat) {
if (stat) { if (stat) {
files = [me._wcurpath]; // success
me._wcurpath = me._wcurpath.replace(files[0], ''); // now try stat on this as a child of the parent directory
child = me._wcurpath.replace(/^.*\/(.*)$/, '$1');
files = [child];
me._wcurpath = parent;
} else { } 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(); me._wReadFiles();

View File

@ -17,7 +17,7 @@
}, },
"lib": ".", "lib": ".",
"main": "./lib/walk.js", "main": "./lib/walk.js",
"version": "2.3.7", "version": "2.3.8",
"repository": { "repository": {
"url": "git://github.com/coolaj86/node-walk.git" "url": "git://github.com/coolaj86/node-walk.git"
}, },