Skip to content

Commit

Permalink
handle non-existing directories
Browse files Browse the repository at this point in the history
fixes #14441
  • Loading branch information
sokra committed Oct 13, 2021
1 parent 1891b64 commit e26ac75
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 29 deletions.
85 changes: 62 additions & 23 deletions lib/FileSystemInfo.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 &&
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
});
Expand All @@ -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 &&
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 = [];
Expand Down
12 changes: 6 additions & 6 deletions types.d.ts
Expand Up @@ -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>;
Expand Down

0 comments on commit e26ac75

Please sign in to comment.