Skip to content

Commit e26ac75

Browse files
committed
handle non-existing directories
fixes #14441
1 parent 1891b64 commit e26ac75

File tree

2 files changed

+68
-29
lines changed

2 files changed

+68
-29
lines changed

lib/FileSystemInfo.js

+62-23
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,17 @@ class Snapshot {
206206
this._flags = 0;
207207
/** @type {number | undefined} */
208208
this.startTime = undefined;
209-
/** @type {Map<string, FileSystemInfoEntry> | undefined} */
209+
/** @type {Map<string, FileSystemInfoEntry | null> | undefined} */
210210
this.fileTimestamps = undefined;
211-
/** @type {Map<string, string> | undefined} */
211+
/** @type {Map<string, string | null> | undefined} */
212212
this.fileHashes = undefined;
213-
/** @type {Map<string, TimestampAndHash | string> | undefined} */
213+
/** @type {Map<string, TimestampAndHash | string | null> | undefined} */
214214
this.fileTshs = undefined;
215-
/** @type {Map<string, ResolvedContextFileSystemInfoEntry> | undefined} */
215+
/** @type {Map<string, ResolvedContextFileSystemInfoEntry | null> | undefined} */
216216
this.contextTimestamps = undefined;
217-
/** @type {Map<string, string> | undefined} */
217+
/** @type {Map<string, string | null> | undefined} */
218218
this.contextHashes = undefined;
219-
/** @type {Map<string, ResolvedContextTimestampAndHash> | undefined} */
219+
/** @type {Map<string, ResolvedContextTimestampAndHash | null> | undefined} */
220220
this.contextTshs = undefined;
221221
/** @type {Map<string, boolean> | undefined} */
222222
this.missingExistence = undefined;
@@ -823,11 +823,10 @@ const getManagedItem = (managedPath, path) => {
823823

824824
/**
825825
* @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T
826-
* @param {T | "ignore"} entry entry
826+
* @param {T} entry entry
827827
* @returns {T["resolved"] | undefined} the resolved entry
828828
*/
829829
const getResolvedTimestamp = entry => {
830-
if (entry === "ignore") return undefined;
831830
if (entry === null) return null;
832831
if (entry.resolved !== undefined) return entry.resolved;
833832
return entry.symlinks === undefined ? entry : undefined;
@@ -1191,6 +1190,7 @@ class FileSystemInfo {
11911190
getContextTimestamp(path, callback) {
11921191
const cache = this._contextTimestamps.get(path);
11931192
if (cache !== undefined) {
1193+
if (cache === "ignore") return callback(null, "ignore");
11941194
const resolved = getResolvedTimestamp(cache);
11951195
if (resolved !== undefined) return callback(null, resolved);
11961196
return this._resolveContextTimestamp(cache, callback);
@@ -1876,17 +1876,17 @@ class FileSystemInfo {
18761876
* @returns {void}
18771877
*/
18781878
createSnapshot(startTime, files, directories, missing, options, callback) {
1879-
/** @type {Map<string, FileSystemInfoEntry>} */
1879+
/** @type {Map<string, FileSystemInfoEntry | null>} */
18801880
const fileTimestamps = new Map();
1881-
/** @type {Map<string, string>} */
1881+
/** @type {Map<string, string | null>} */
18821882
const fileHashes = new Map();
1883-
/** @type {Map<string, TimestampAndHash | string>} */
1883+
/** @type {Map<string, TimestampAndHash | string | null>} */
18841884
const fileTshs = new Map();
1885-
/** @type {Map<string, FileSystemInfoEntry>} */
1885+
/** @type {Map<string, FileSystemInfoEntry | null>} */
18861886
const contextTimestamps = new Map();
1887-
/** @type {Map<string, string>} */
1887+
/** @type {Map<string, string | null>} */
18881888
const contextHashes = new Map();
1889-
/** @type {Map<string, TimestampAndHash | string>} */
1889+
/** @type {Map<string, ResolvedContextTimestampAndHash | null>} */
18901890
const contextTshs = new Map();
18911891
/** @type {Map<string, boolean>} */
18921892
const missingExistence = new Map();
@@ -2080,6 +2080,7 @@ class FileSystemInfo {
20802080
this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
20812081
for (const path of capturedDirectories) {
20822082
const cache = this._contextTshs.get(path);
2083+
/** @type {ResolvedContextTimestampAndHash} */
20832084
let resolved;
20842085
if (
20852086
cache !== undefined &&
@@ -2088,6 +2089,11 @@ class FileSystemInfo {
20882089
contextTshs.set(path, resolved);
20892090
} else {
20902091
jobs++;
2092+
/**
2093+
* @param {Error=} err error
2094+
* @param {ResolvedContextTimestampAndHash=} entry entry
2095+
* @returns {void}
2096+
*/
20912097
const callback = (err, entry) => {
20922098
if (err) {
20932099
if (this.logger) {
@@ -2152,14 +2158,20 @@ class FileSystemInfo {
21522158
);
21532159
for (const path of capturedDirectories) {
21542160
const cache = this._contextTimestamps.get(path);
2161+
if (cache === "ignore") continue;
21552162
let resolved;
21562163
if (
21572164
cache !== undefined &&
21582165
(resolved = getResolvedTimestamp(cache)) !== undefined
21592166
) {
21602167
contextTimestamps.set(path, resolved);
2161-
} else if (cache !== "ignore") {
2168+
} else {
21622169
jobs++;
2170+
/**
2171+
* @param {Error=} err error
2172+
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
2173+
* @returns {void}
2174+
*/
21632175
const callback = (err, entry) => {
21642176
if (err) {
21652177
if (this.logger) {
@@ -2572,14 +2584,14 @@ class FileSystemInfo {
25722584
const cache = this._fileTimestamps.get(path);
25732585
if (cache !== undefined) {
25742586
if (cache === "ignore" || !checkFile(path, cache, tsh, false)) {
2575-
processFileHashSnapshot(path, tsh.hash);
2587+
processFileHashSnapshot(path, tsh && tsh.hash);
25762588
}
25772589
} else {
25782590
jobs++;
25792591
this.fileTimestampQueue.add(path, (err, entry) => {
25802592
if (err) return invalidWithError(path, err);
25812593
if (!checkFile(path, entry, tsh, false)) {
2582-
processFileHashSnapshot(path, tsh.hash);
2594+
processFileHashSnapshot(path, tsh && tsh.hash);
25832595
}
25842596
jobDone();
25852597
});
@@ -2592,6 +2604,7 @@ class FileSystemInfo {
25922604
this._statTestedEntries += contextTimestamps.size;
25932605
for (const [path, ts] of contextTimestamps) {
25942606
const cache = this._contextTimestamps.get(path);
2607+
if (cache === "ignore") continue;
25952608
let resolved;
25962609
if (
25972610
cache !== undefined &&
@@ -2601,8 +2614,13 @@ class FileSystemInfo {
26012614
invalid();
26022615
return;
26032616
}
2604-
} else if (cache !== "ignore") {
2617+
} else {
26052618
jobs++;
2619+
/**
2620+
* @param {Error=} err error
2621+
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
2622+
* @returns {void}
2623+
*/
26062624
const callback = (err, entry) => {
26072625
if (err) return invalidWithError(path, err);
26082626
if (!checkContext(path, entry, ts)) {
@@ -2662,27 +2680,33 @@ class FileSystemInfo {
26622680
processContextHashSnapshot(path, tsh);
26632681
} else {
26642682
const cache = this._contextTimestamps.get(path);
2683+
if (cache === "ignore") continue;
26652684
let resolved;
26662685
if (
26672686
cache !== undefined &&
26682687
(resolved = getResolvedTimestamp(cache)) !== undefined
26692688
) {
26702689
if (!checkContext(path, resolved, tsh, false)) {
2671-
processContextHashSnapshot(path, tsh.hash);
2690+
processContextHashSnapshot(path, tsh && tsh.hash);
26722691
}
2673-
} else if (cache !== "ignore") {
2692+
} else {
26742693
jobs++;
2694+
/**
2695+
* @param {Error=} err error
2696+
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
2697+
* @returns {void}
2698+
*/
26752699
const callback = (err, entry) => {
26762700
if (err) return invalidWithError(path, err);
26772701
if (!checkContext(path, entry, tsh, false)) {
2678-
processContextHashSnapshot(path, tsh.hash);
2702+
processContextHashSnapshot(path, tsh && tsh.hash);
26792703
}
26802704
jobDone();
26812705
};
26822706
if (cache !== undefined) {
2683-
this._resolveContextTsh(cache, callback);
2707+
this._resolveContextTimestamp(cache, callback);
26842708
} else {
2685-
this.getContextTsh(path, callback);
2709+
this.getContextTimestamp(path, callback);
26862710
}
26872711
}
26882712
}
@@ -3032,6 +3056,11 @@ class FileSystemInfo {
30323056
);
30333057
}
30343058

3059+
/**
3060+
* @param {ContextFileSystemInfoEntry} entry entry
3061+
* @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3062+
* @returns {void}
3063+
*/
30353064
_resolveContextTimestamp(entry, callback) {
30363065
const hashes = [];
30373066
let safeTime = 0;
@@ -3135,6 +3164,11 @@ class FileSystemInfo {
31353164
);
31363165
}
31373166

3167+
/**
3168+
* @param {ContextHash} entry context hash
3169+
* @param {function(Error=, string=): void} callback callback
3170+
* @returns {void}
3171+
*/
31383172
_resolveContextHash(entry, callback) {
31393173
const hashes = [];
31403174
processAsyncTree(
@@ -3286,6 +3320,11 @@ class FileSystemInfo {
32863320
}
32873321
}
32883322

3323+
/**
3324+
* @param {ContextTimestampAndHash} entry entry
3325+
* @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback
3326+
* @returns {void}
3327+
*/
32893328
_resolveContextTsh(entry, callback) {
32903329
const hashes = [];
32913330
const tsHashes = [];

types.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -10448,12 +10448,12 @@ declare class SizeOnlySource extends Source {
1044810448
}
1044910449
declare abstract class Snapshot {
1045010450
startTime?: number;
10451-
fileTimestamps?: Map<string, FileSystemInfoEntry>;
10452-
fileHashes?: Map<string, string>;
10453-
fileTshs?: Map<string, string | TimestampAndHash>;
10454-
contextTimestamps?: Map<string, ResolvedContextFileSystemInfoEntry>;
10455-
contextHashes?: Map<string, string>;
10456-
contextTshs?: Map<string, ResolvedContextTimestampAndHash>;
10451+
fileTimestamps?: Map<string, null | FileSystemInfoEntry>;
10452+
fileHashes?: Map<string, null | string>;
10453+
fileTshs?: Map<string, null | string | TimestampAndHash>;
10454+
contextTimestamps?: Map<string, null | ResolvedContextFileSystemInfoEntry>;
10455+
contextHashes?: Map<string, null | string>;
10456+
contextTshs?: Map<string, null | ResolvedContextTimestampAndHash>;
1045710457
missingExistence?: Map<string, boolean>;
1045810458
managedItemInfo?: Map<string, string>;
1045910459
managedFiles?: Set<string>;

0 commit comments

Comments
 (0)