From a33cd4337b096d2ccb61387afee958bcf1f279d1 Mon Sep 17 00:00:00 2001 From: Matthew Beale Date: Sat, 8 Aug 2015 16:00:40 -0400 Subject: [PATCH] Do not descend ignored directories Paths may be ignored because they contain a large number of files. The getDirs method should not actually descend into those ignored directories. Additionally this commit flattens the recursion in getDirs. --- lib/utils.js | 69 +++++++++++++------------ tests/builder.js | 7 ++- tests/input/with-symlink/a/.gitignore | 0 tests/input/with-symlink/a/b | 1 + tests/input/with-symlink/a/d/.gitignore | 0 tests/input/with-symlink/a/some-file | 0 tests/input/with-symlink/c/.gitignore | 0 tests/input/with-symlink/some-file | 0 tests/parser.js | 9 +++- tests/utils.js | 55 +++++++++++++++++++- 10 files changed, 105 insertions(+), 36 deletions(-) create mode 100644 tests/input/with-symlink/a/.gitignore create mode 120000 tests/input/with-symlink/a/b create mode 100644 tests/input/with-symlink/a/d/.gitignore create mode 100644 tests/input/with-symlink/a/some-file create mode 100644 tests/input/with-symlink/c/.gitignore create mode 100644 tests/input/with-symlink/some-file diff --git a/lib/utils.js b/lib/utils.js index 328a409e..a45264f9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -336,27 +336,45 @@ YUI.add('utils', function (Y) { Y.getProjectData = getProjectData; - /** * Walks the tree from this dir and returns all the subdirs * @method getDirs - * @param {String} dir The dir to begin at + * @param {String} baseDir The dir to begin at + * @param {Array} ignore An array of paths to ignore * @return {Array} The array of directories.. */ - var getDirs = function (dir) { - var dirs = fs.readdirSync(dir), - paths = []; + var getDirs = function (baseDir, ignore) { + var inputPaths = [], + paths = [], + i, d, isIgnored, subpath, + stat, possibleDirs, fullPath; - dirs.forEach(function (d) { - var _dir = path.join(dir, d), - stat = fs.lstatSync(_dir); + var inputPath = ''; + while (inputPath !== undefined) { + fullPath = path.join(baseDir, inputPath); + stat = fs.lstatSync(fullPath); if (stat.isDirectory()) { - if (_dir.indexOf('.') !== 0) { - paths = [].concat(paths, _dir, getDirs(_dir)); + if (fullPath !== baseDir) { + paths.push(fullPath); + } + possibleDirs = fs.readdirSync(fullPath); + for (d=0;d