Tolerate ENOENT errors in Builder#copyDirectory.

This commit is contained in:
Ben Newman
2016-11-08 13:33:20 -05:00
parent 6ce7891d9b
commit a7ac32e00a
2 changed files with 20 additions and 5 deletions

View File

@@ -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) => {

View File

@@ -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) {