Skip to content

Commit

Permalink
Don't shell out for find
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashko Stubailo committed Jan 29, 2015
1 parent 6b876c7 commit 4b1f257
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
45 changes: 45 additions & 0 deletions tools/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,51 @@ files.cp_r = function (from, to, options) {
});
};

// Get every path in dir recursively
files.getPathsInDir = function (dir, options) {
if (! files.exists(dir)) {
// There are no paths in this dir, so don't do anything
return;
}

var oldCwd = process.cwd();

var cwd = options && options.cwd;
if (cwd) {
if (! files.exists(cwd)) {
throw new Error("Specified current working directory doesn't exist:" +
cwd);
}

process.chdir(cwd);
}

var output = [];

_.each(files.readdir(dir), function (entry) {
var newPath = files.pathJoin(dir, entry);
output.push(newPath);

if (files.stat(newPath).isDirectory()) {
output = output.concat(files.getPathsInDir(newPath));
}
});

process.chdir(oldCwd);

return output;
};

files.findPathsWithRegex = function (dir, regex, options) {
var allPaths = files.getPathsInDir(dir, {
cwd: options.cwd
});

return _.filter(allPaths, function (path) {
return path.match(regex);
});
};

// Copies a file, which is expected to exist. Parent directories of "to" do not
// have to exist. Treats symbolic links transparently (copies the contents, not
// the link itself, and it's an error if the link doesn't point to a file).
Expand Down
16 changes: 7 additions & 9 deletions tools/meteor-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,15 @@ var installNpmModule = function (name, version, dir) {
if (process.platform !== "win32") {
// If we are on a unixy file system, we should not build a package that
// can't be used on Windows.
var output = utils.execFileSync("bash", ["-c", "find . | grep ':'"],
{cwd: files.pathJoin(dir, "node_modules", name)});

console.log(files.pathJoin(dir, name));
var pathsWithColons = files.findPathsWithRegex(".", new RegExp(":"),
{ cwd: dir });

if (output.success) {
var lines = output.stdout.split("\n");

var firstTen = lines.slice(0, 10);
if (lines.length > 10) {
firstTen.push("... " + (lines.length - 10) + " paths omitted.");
if (pathsWithColons.length) {
var firstTen = pathsWithColons.slice(0, 10);
if (pathsWithColons.length > 10) {
firstTen.push("... " + (pathsWithColons.length - 10) +
" paths omitted.");
}

buildmessage.error(
Expand Down

0 comments on commit 4b1f257

Please sign in to comment.