Skip to content

Commit 8eaab85

Browse files
authored
fix: Avoid pushing additional paths to queue when error occurs (#124)
1 parent d49d9bd commit 8eaab85

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

index.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var globParent = require('glob-parent');
1212
var normalizePath = require('normalize-path');
1313
var isNegatedGlob = require('is-negated-glob');
1414
var toAbsoluteGlob = require('@gulpjs/to-absolute-glob');
15+
var mapSeries = require('now-and-later').mapSeries;
1516

1617
var globErrMessage1 = 'File not found with singular glob: ';
1718
var globErrMessage2 = ' (if this was purposeful, use `allowEmpty` option)';
@@ -55,6 +56,14 @@ function walkdir() {
5556
queue.push(filepath);
5657
};
5758

59+
function isDefined(value) {
60+
return typeof value !== 'undefined';
61+
}
62+
63+
function queuePush(value) {
64+
queue.push(value);
65+
}
66+
5867
function readdir(filepath, cb) {
5968
fs.readdir(filepath, readdirOpts, onReaddir);
6069

@@ -63,29 +72,45 @@ function walkdir() {
6372
return cb(err);
6473
}
6574

66-
dirents.forEach(processDirent);
75+
mapSeries(dirents, processDirents, function (err, dirs) {
76+
if (err) {
77+
return cb(err);
78+
}
6779

68-
cb();
80+
dirs.filter(isDefined).forEach(queuePush);
81+
82+
cb();
83+
});
6984
}
7085

71-
function processDirent(dirent) {
86+
function processDirents(dirent, key, cb) {
7287
var nextpath = path.join(filepath, dirent.name);
7388
ee.emit('path', nextpath, dirent);
7489

7590
if (dirent.isDirectory()) {
76-
queue.push(nextpath);
77-
} else if (dirent.isSymbolicLink()) {
91+
cb(null, nextpath);
92+
93+
return;
94+
}
95+
96+
if (dirent.isSymbolicLink()) {
7897
// If it's a symlink, check if the symlink points to a directory
7998
fs.stat(nextpath, function (err, stats) {
8099
if (err) {
81100
return cb(err);
82101
}
83102

84103
if (stats.isDirectory()) {
85-
queue.push(nextpath);
104+
cb(null, nextpath);
105+
} else {
106+
cb();
86107
}
87108
});
109+
110+
return;
88111
}
112+
113+
cb();
89114
}
90115
}
91116

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"is-glob": "^4.0.3",
3131
"is-negated-glob": "^1.0.0",
3232
"normalize-path": "^3.0.0",
33+
"now-and-later": "^3.0.0",
3334
"streamx": "^2.12.5"
3435
},
3536
"devDependencies": {

0 commit comments

Comments
 (0)