From a7ac32e00a87384956fdf65dfdf2198c98d73d6f Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 8 Nov 2016 13:33:20 -0500 Subject: [PATCH] Tolerate ENOENT errors in Builder#copyDirectory. --- tools/fs/optimistic.js | 8 ++++++++ tools/isobuild/builder.js | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/fs/optimistic.js b/tools/fs/optimistic.js index 687016366f..74290628a2 100644 --- a/tools/fs/optimistic.js +++ b/tools/fs/optimistic.js @@ -174,6 +174,14 @@ export function dirtyNodeModulesDirectory(nodeModulesDir) { export const optimisticStatOrNull = makeOptimistic("statOrNull", statOrNull); export const optimisticLStat = makeOptimistic("lstat", lstat); +export const optimisticLStatOrNull = makeOptimistic("lstatOrNull", path => { + try { + return optimisticLStat(path); + } catch (e) { + if (e.code !== "ENOENT") throw e; + return null; + } +}); export const optimisticReadFile = makeOptimistic("readFile", readFile); export const optimisticReaddir = makeOptimistic("readdir", readdir); export const optimisticHashOrNull = makeOptimistic("hashOrNull", (...args) => { diff --git a/tools/isobuild/builder.js b/tools/isobuild/builder.js index 8136e3d2fd..f964f2a671 100644 --- a/tools/isobuild/builder.js +++ b/tools/isobuild/builder.js @@ -6,7 +6,7 @@ import {Profile} from '../tool-env/profile.js'; import { optimisticReadFile, optimisticReaddir, - optimisticLStat, + optimisticLStatOrNull, } from "../fs/optimistic.js"; // Builder is in charge of writing "bundles" to disk, which are @@ -497,9 +497,11 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}` return cachedExternalPath = isExternal && real; }; - let fileStatus = optimisticLStat(thisAbsFrom); + let fileStatus = optimisticLStatOrNull(thisAbsFrom); - if (! symlink && fileStatus.isSymbolicLink()) { + if (! symlink && + fileStatus && + fileStatus.isSymbolicLink()) { // If copyDirectory is not allowed to create symbolic links to // external files, and this file is a symbolic link that points // to an external file, update fileStatus so that we copy this @@ -512,9 +514,9 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}` // Update fileStatus to match the actual file rather than the // symbolic link, thus forcing the file to be copied below. - fileStatus = optimisticLStat(externalPath); + fileStatus = optimisticLStatOrNull(externalPath); - if (fileStatus.isDirectory()) { + if (fileStatus && fileStatus.isDirectory()) { // Update _currentRealRootDir so that we can judge // isExternal relative to this new root directory when // traversing nested directories. @@ -523,6 +525,11 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}` } } + if (! fileStatus) { + // If the file did not exist, skip it. + return; + } + let itemForMatch = item; const isDirectory = fileStatus.isDirectory(); if (isDirectory) {