Skip to content

Commit bdffaf3

Browse files
author
Rachel Macfarlane
committed
Ensure no more than MAX_FILES are read when collecting workspace stats, microsoft#79456
1 parent 0ec80b4 commit bdffaf3

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

src/vs/platform/diagnostics/node/diagnosticsService.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,26 @@ export function collectWorkspaceStats(folder: string, filter: string[]): Promise
7676
return done(results);
7777
}
7878

79+
if (token.count > MAX_FILES) {
80+
token.maxReached = true;
81+
return done(results);
82+
}
83+
7984
let pending = files.length;
8085
if (pending === 0) {
8186
return done(results);
8287
}
8388

84-
for (const file of files) {
85-
if (token.maxReached) {
86-
return done(results);
87-
}
89+
let filesToRead = files;
90+
if (token.count + files.length > MAX_FILES) {
91+
token.maxReached = true;
92+
pending = MAX_FILES - token.count;
93+
filesToRead = files.slice(0, pending);
94+
}
95+
96+
token.count += files.length;
8897

98+
for (const file of filesToRead) {
8999
stat(join(dir, file), (err, stats) => {
90100
// Ignore files that can't be read
91101
if (err) {
@@ -108,11 +118,6 @@ export function collectWorkspaceStats(folder: string, filter: string[]): Promise
108118
}
109119
}
110120
} else {
111-
if (token.count >= MAX_FILES) {
112-
token.maxReached = true;
113-
}
114-
115-
token.count++;
116121
results.push(file);
117122

118123
if (--pending === 0) {

0 commit comments

Comments
 (0)