Skip to content

Commit

Permalink
Tolerate ENOENT errors in Builder#copyDirectory.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Newman committed Nov 8, 2016
1 parent 6ce7891 commit a7ac32e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 8 additions & 0 deletions tools/fs/optimistic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
17 changes: 12 additions & 5 deletions tools/isobuild/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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) {
Expand Down

0 comments on commit a7ac32e

Please sign in to comment.