From 978df6e043ecc2fc11b352e6ca89d4f63f915252 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 26 Sep 2016 17:35:51 -0400 Subject: [PATCH] Use optimistic functions in meteorNpm.isPortable. --- tools/fs/optimistic.js | 2 ++ tools/isobuild/meteor-npm.js | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/fs/optimistic.js b/tools/fs/optimistic.js index 040ceeb14a..a96886cc09 100644 --- a/tools/fs/optimistic.js +++ b/tools/fs/optimistic.js @@ -7,6 +7,7 @@ import { pathSep, pathIsAbsolute, statOrNull, + lstat, readFile, readdir, } from "./files.js"; @@ -123,6 +124,7 @@ function makeCacheKey(args) { } export const optimisticStatOrNull = makeOptimistic("statOrNull", statOrNull); +export const optimisticLStat = makeOptimistic("lstat", lstat); export const optimisticReadFile = makeOptimistic("readFile", readFile); export const optimisticReaddir = makeOptimistic("readdir", readdir); export const optimisticHashOrNull = makeOptimistic("hashOrNull", path => { diff --git a/tools/isobuild/meteor-npm.js b/tools/isobuild/meteor-npm.js index a6d0c77f26..88cc420692 100644 --- a/tools/isobuild/meteor-npm.js +++ b/tools/isobuild/meteor-npm.js @@ -22,6 +22,13 @@ import { convert as convertColonsInPath } from "../utils/colon-converter.js"; +import { + optimisticLStat, + optimisticStatOrNull, + optimisticReadFile, + optimisticReaddir, +} from "../fs/optimistic.js"; + var meteorNpm = exports; // if a user exits meteor while we're trying to create a .npm @@ -429,14 +436,14 @@ function copyNpmPackageWithSymlinkedNodeModules(fromPkgDir, toPkgDir) { }); } -function isPortable(dir) { - const lstat = files.lstat(dir); +const isPortable = Profile("meteorNpm.isPortable", dir => { + const lstat = optimisticLStat(dir); if (! lstat.isDirectory()) { // Non-directory files are portable unless they end with .node. return ! dir.endsWith(".node"); } - const pkgJsonStat = files.statOrNull(files.pathJoin(dir, "package.json")); + const pkgJsonStat = optimisticStatOrNull(files.pathJoin(dir, "package.json")); const canCache = pkgJsonStat && pkgJsonStat.isFile(); const portableFile = files.pathJoin(dir, ".meteor-portable"); @@ -448,7 +455,7 @@ function isPortable(dir) { // directories, so that they will get cleared away the next time those // packages are (re)installed. try { - return JSON.parse(files.readFile(portableFile)); + return JSON.parse(optimisticReadFile(portableFile)); } catch (e) { if (! (e instanceof SyntaxError || e.code === "ENOENT")) { @@ -461,7 +468,7 @@ function isPortable(dir) { fs.unlink(portableFile, error => {}); } - const result = files.readdir(dir).every( + const result = optimisticReaddir(dir).every( // Ignore files that start with a ".", such as .bin directories. itemName => itemName.startsWith(".") || isPortable(files.pathJoin(dir, itemName))); @@ -478,7 +485,7 @@ function isPortable(dir) { } return result; -} +}); // Return true if all of a package's npm dependencies are portable // (that is, if the node_modules can be copied anywhere and we'd