handle non-existing directories

fixes #14441
This commit is contained in:
Tobias Koppers 2021-10-13 10:25:25 +02:00
parent 1891b64d6b
commit e26ac7540a
2 changed files with 68 additions and 29 deletions

View File

@ -206,17 +206,17 @@ class Snapshot {
this._flags = 0;
/** @type {number | undefined} */
this.startTime = undefined;
/** @type {Map<string, FileSystemInfoEntry> | undefined} */
/** @type {Map<string, FileSystemInfoEntry | null> | undefined} */
this.fileTimestamps = undefined;
/** @type {Map<string, string> | undefined} */
/** @type {Map<string, string | null> | undefined} */
this.fileHashes = undefined;
/** @type {Map<string, TimestampAndHash | string> | undefined} */
/** @type {Map<string, TimestampAndHash | string | null> | undefined} */
this.fileTshs = undefined;
/** @type {Map<string, ResolvedContextFileSystemInfoEntry> | undefined} */
/** @type {Map<string, ResolvedContextFileSystemInfoEntry | null> | undefined} */
this.contextTimestamps = undefined;
/** @type {Map<string, string> | undefined} */
/** @type {Map<string, string | null> | undefined} */
this.contextHashes = undefined;
/** @type {Map<string, ResolvedContextTimestampAndHash> | undefined} */
/** @type {Map<string, ResolvedContextTimestampAndHash | null> | undefined} */
this.contextTshs = undefined;
/** @type {Map<string, boolean> | undefined} */
this.missingExistence = undefined;
@ -823,11 +823,10 @@ const getManagedItem = (managedPath, path) => {
/**
* @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T
* @param {T | "ignore"} entry entry
* @param {T} entry entry
* @returns {T["resolved"] | undefined} the resolved entry
*/
const getResolvedTimestamp = entry => {
if (entry === "ignore") return undefined;
if (entry === null) return null;
if (entry.resolved !== undefined) return entry.resolved;
return entry.symlinks === undefined ? entry : undefined;
@ -1191,6 +1190,7 @@ class FileSystemInfo {
getContextTimestamp(path, callback) {
const cache = this._contextTimestamps.get(path);
if (cache !== undefined) {
if (cache === "ignore") return callback(null, "ignore");
const resolved = getResolvedTimestamp(cache);
if (resolved !== undefined) return callback(null, resolved);
return this._resolveContextTimestamp(cache, callback);
@ -1876,17 +1876,17 @@ class FileSystemInfo {
* @returns {void}
*/
createSnapshot(startTime, files, directories, missing, options, callback) {
/** @type {Map<string, FileSystemInfoEntry>} */
/** @type {Map<string, FileSystemInfoEntry | null>} */
const fileTimestamps = new Map();
/** @type {Map<string, string>} */
/** @type {Map<string, string | null>} */
const fileHashes = new Map();
/** @type {Map<string, TimestampAndHash | string>} */
/** @type {Map<string, TimestampAndHash | string | null>} */
const fileTshs = new Map();
/** @type {Map<string, FileSystemInfoEntry>} */
/** @type {Map<string, FileSystemInfoEntry | null>} */
const contextTimestamps = new Map();
/** @type {Map<string, string>} */
/** @type {Map<string, string | null>} */
const contextHashes = new Map();
/** @type {Map<string, TimestampAndHash | string>} */
/** @type {Map<string, ResolvedContextTimestampAndHash | null>} */
const contextTshs = new Map();
/** @type {Map<string, boolean>} */
const missingExistence = new Map();
@ -2080,6 +2080,7 @@ class FileSystemInfo {
this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
for (const path of capturedDirectories) {
const cache = this._contextTshs.get(path);
/** @type {ResolvedContextTimestampAndHash} */
let resolved;
if (
cache !== undefined &&
@ -2088,6 +2089,11 @@ class FileSystemInfo {
contextTshs.set(path, resolved);
} else {
jobs++;
/**
* @param {Error=} err error
* @param {ResolvedContextTimestampAndHash=} entry entry
* @returns {void}
*/
const callback = (err, entry) => {
if (err) {
if (this.logger) {
@ -2152,14 +2158,20 @@ class FileSystemInfo {
);
for (const path of capturedDirectories) {
const cache = this._contextTimestamps.get(path);
if (cache === "ignore") continue;
let resolved;
if (
cache !== undefined &&
(resolved = getResolvedTimestamp(cache)) !== undefined
) {
contextTimestamps.set(path, resolved);
} else if (cache !== "ignore") {
} else {
jobs++;
/**
* @param {Error=} err error
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
* @returns {void}
*/
const callback = (err, entry) => {
if (err) {
if (this.logger) {
@ -2572,14 +2584,14 @@ class FileSystemInfo {
const cache = this._fileTimestamps.get(path);
if (cache !== undefined) {
if (cache === "ignore" || !checkFile(path, cache, tsh, false)) {
processFileHashSnapshot(path, tsh.hash);
processFileHashSnapshot(path, tsh && tsh.hash);
}
} else {
jobs++;
this.fileTimestampQueue.add(path, (err, entry) => {
if (err) return invalidWithError(path, err);
if (!checkFile(path, entry, tsh, false)) {
processFileHashSnapshot(path, tsh.hash);
processFileHashSnapshot(path, tsh && tsh.hash);
}
jobDone();
});
@ -2592,6 +2604,7 @@ class FileSystemInfo {
this._statTestedEntries += contextTimestamps.size;
for (const [path, ts] of contextTimestamps) {
const cache = this._contextTimestamps.get(path);
if (cache === "ignore") continue;
let resolved;
if (
cache !== undefined &&
@ -2601,8 +2614,13 @@ class FileSystemInfo {
invalid();
return;
}
} else if (cache !== "ignore") {
} else {
jobs++;
/**
* @param {Error=} err error
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
* @returns {void}
*/
const callback = (err, entry) => {
if (err) return invalidWithError(path, err);
if (!checkContext(path, entry, ts)) {
@ -2662,27 +2680,33 @@ class FileSystemInfo {
processContextHashSnapshot(path, tsh);
} else {
const cache = this._contextTimestamps.get(path);
if (cache === "ignore") continue;
let resolved;
if (
cache !== undefined &&
(resolved = getResolvedTimestamp(cache)) !== undefined
) {
if (!checkContext(path, resolved, tsh, false)) {
processContextHashSnapshot(path, tsh.hash);
processContextHashSnapshot(path, tsh && tsh.hash);
}
} else if (cache !== "ignore") {
} else {
jobs++;
/**
* @param {Error=} err error
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
* @returns {void}
*/
const callback = (err, entry) => {
if (err) return invalidWithError(path, err);
if (!checkContext(path, entry, tsh, false)) {
processContextHashSnapshot(path, tsh.hash);
processContextHashSnapshot(path, tsh && tsh.hash);
}
jobDone();
};
if (cache !== undefined) {
this._resolveContextTsh(cache, callback);
this._resolveContextTimestamp(cache, callback);
} else {
this.getContextTsh(path, callback);
this.getContextTimestamp(path, callback);
}
}
}
@ -3032,6 +3056,11 @@ class FileSystemInfo {
);
}
/**
* @param {ContextFileSystemInfoEntry} entry entry
* @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback
* @returns {void}
*/
_resolveContextTimestamp(entry, callback) {
const hashes = [];
let safeTime = 0;
@ -3135,6 +3164,11 @@ class FileSystemInfo {
);
}
/**
* @param {ContextHash} entry context hash
* @param {function(Error=, string=): void} callback callback
* @returns {void}
*/
_resolveContextHash(entry, callback) {
const hashes = [];
processAsyncTree(
@ -3286,6 +3320,11 @@ class FileSystemInfo {
}
}
/**
* @param {ContextTimestampAndHash} entry entry
* @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback
* @returns {void}
*/
_resolveContextTsh(entry, callback) {
const hashes = [];
const tsHashes = [];

12
types.d.ts vendored
View File

@ -10448,12 +10448,12 @@ declare class SizeOnlySource extends Source {
}
declare abstract class Snapshot {
startTime?: number;
fileTimestamps?: Map<string, FileSystemInfoEntry>;
fileHashes?: Map<string, string>;
fileTshs?: Map<string, string | TimestampAndHash>;
contextTimestamps?: Map<string, ResolvedContextFileSystemInfoEntry>;
contextHashes?: Map<string, string>;
contextTshs?: Map<string, ResolvedContextTimestampAndHash>;
fileTimestamps?: Map<string, null | FileSystemInfoEntry>;
fileHashes?: Map<string, null | string>;
fileTshs?: Map<string, null | string | TimestampAndHash>;
contextTimestamps?: Map<string, null | ResolvedContextFileSystemInfoEntry>;
contextHashes?: Map<string, null | string>;
contextTshs?: Map<string, null | ResolvedContextTimestampAndHash>;
missingExistence?: Map<string, boolean>;
managedItemInfo?: Map<string, string>;
managedFiles?: Set<string>;