Skip to content

Commit 056df12

Browse files
Prevent bootstrapped extension from being downloaded multiple times (#7229)
1 parent a6e0c80 commit 056df12

File tree

2 files changed

+43
-26
lines changed

2 files changed

+43
-26
lines changed

build/lib/bootstrapExtensions.js

Lines changed: 22 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/bootstrapExtensions.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,31 @@ function getExtensionPath(extension: IExtensionDefinition): string {
3535

3636
function isUpToDate(extension: IExtensionDefinition): boolean {
3737
const regex = new RegExp(`^${extension.name}-(\\d+\\.\\d+\\.\\d+)\\.vsix$`);
38-
if (!fs.existsSync(path.join(root, '.build', 'bootstrapExtensions'))) {
38+
const bootstrapDir = path.join(root, '.build', 'bootstrapExtensions');
39+
if (!fs.existsSync(bootstrapDir)) {
3940
return false;
4041
}
41-
const files = fs.readdirSync(path.join(root, '.build', 'bootstrapExtensions'));
42-
const vsixPath = files.find(f => regex.test(f));
4342

44-
if (!vsixPath) {
45-
return false;
46-
}
47-
48-
try {
49-
const match = vsixPath.match(regex);
50-
const diskVersion = match ? match[1] : null;
51-
return (diskVersion === extension.version);
52-
} catch (err) {
53-
return false;
43+
const files = fs.readdirSync(bootstrapDir);
44+
const matchingFiles = files.filter(f => regex.test(f));
45+
for (const vsixPath of matchingFiles) {
46+
try {
47+
const match = vsixPath.match(regex);
48+
const diskVersion = match ? match[1] : null;
49+
50+
if (diskVersion !== extension.version) {
51+
log(`[extensions]`, `Outdated version detected, deleting ${vsixPath}`);
52+
fs.unlinkSync(path.join(bootstrapDir, vsixPath));
53+
} else {
54+
log(`[extensions]`, `Found up-to-date extension: ${vsixPath}`);
55+
return true;
56+
}
57+
} catch (err) {
58+
log(`[extensions]`, `Error checking version of ${vsixPath}`, err);
59+
return false;
60+
}
5461
}
62+
return false;
5563
}
5664

5765
function getExtensionDownloadStream(extension: IExtensionDefinition) {

0 commit comments

Comments
 (0)