Skip to content

Commit

Permalink
fix: Avoid pushing additional paths to queue when error occurs (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored Mar 25, 2024
1 parent d49d9bd commit 8eaab85
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
37 changes: 31 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var globParent = require('glob-parent');
var normalizePath = require('normalize-path');
var isNegatedGlob = require('is-negated-glob');
var toAbsoluteGlob = require('@gulpjs/to-absolute-glob');
var mapSeries = require('now-and-later').mapSeries;

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

function isDefined(value) {
return typeof value !== 'undefined';
}

function queuePush(value) {
queue.push(value);
}

function readdir(filepath, cb) {
fs.readdir(filepath, readdirOpts, onReaddir);

Expand All @@ -63,29 +72,45 @@ function walkdir() {
return cb(err);
}

dirents.forEach(processDirent);
mapSeries(dirents, processDirents, function (err, dirs) {
if (err) {
return cb(err);
}

cb();
dirs.filter(isDefined).forEach(queuePush);

cb();
});
}

function processDirent(dirent) {
function processDirents(dirent, key, cb) {
var nextpath = path.join(filepath, dirent.name);
ee.emit('path', nextpath, dirent);

if (dirent.isDirectory()) {
queue.push(nextpath);
} else if (dirent.isSymbolicLink()) {
cb(null, nextpath);

return;
}

if (dirent.isSymbolicLink()) {
// If it's a symlink, check if the symlink points to a directory
fs.stat(nextpath, function (err, stats) {
if (err) {
return cb(err);
}

if (stats.isDirectory()) {
queue.push(nextpath);
cb(null, nextpath);
} else {
cb();
}
});

return;
}

cb();
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"is-glob": "^4.0.3",
"is-negated-glob": "^1.0.0",
"normalize-path": "^3.0.0",
"now-and-later": "^3.0.0",
"streamx": "^2.12.5"
},
"devDependencies": {
Expand Down

0 comments on commit 8eaab85

Please sign in to comment.