From 0d6bda5385d59416782a80a57cd6887a67d21c17 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 5 Jan 2015 18:15:46 -0700 Subject: [PATCH] fix #41 by reporting nodeError if first directory fails --- lib/walk.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/walk.js b/lib/walk.js index fc75f8b..7638c2b 100644 --- a/lib/walk.js +++ b/lib/walk.js @@ -159,25 +159,31 @@ me._wfnodegroups = fnodeGroups; me._wcurfiles = files; - + // no error, great if (!err) { me._wReadFiles(); return; } + // error? not first run? => directory error if (!me._wfirstrun) { me.emit('directoryError', me._wcurpath, { error: err }, noop); me._wReadFiles(); return; } + // error? first run? => maybe a file, maybe a true error me._wfirstrun = false; - // TODO how to remove this anony? + + // readdir failed, try stat (might be a file) + me._wcurpath = me._wcurpath.replace(/^.*\/$/, ''); fs[me._wStat](me._wcurpath, function (e, stat) { if (stat) { - files = [me._wcurpath.replace(/.*\//, '')]; + files = [me._wcurpath]; me._wcurpath = me._wcurpath.replace(files[0], ''); + } else { + me.emit('nodeError', me._wcurpath, { error: err }, noop); } me._wReadFiles();