Skip to content

Commit 1d4c111

Browse files
authored
prevent versionManager from installing same version of exe concurrently
The concurrent installations would operate on the same folder overwriting each other causing signature verification to fail for both. Closes #425
1 parent 554886b commit 1d4c111

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/versionManager.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const chmod = util.promisify(fs.chmod);
2626

2727
/** The maxmimum number of installation that can be store until they will be removed */
2828
const maxInstallCount = 5;
29+
/** Maps concurrent requests to install a version of an exe to a single promise */
30+
const inProgressInstalls = new Map<string, Promise<string>>();
2931

3032
export interface Config {
3133
context: vscode.ExtensionContext;
@@ -50,6 +52,21 @@ export interface Config {
5052

5153
/** Returns the path to the executable */
5254
export async function install(config: Config, version: semver.SemVer): Promise<string> {
55+
const key = config.exeName + version.raw;
56+
const entry = inProgressInstalls.get(key);
57+
if (entry) {
58+
return await entry;
59+
}
60+
61+
const promise = installGuarded(config, version);
62+
inProgressInstalls.set(key, promise);
63+
64+
return await promise.finally(() => {
65+
inProgressInstalls.delete(key);
66+
});
67+
}
68+
69+
async function installGuarded(config: Config, version: semver.SemVer): Promise<string> {
5370
const exeName = config.exeName + (process.platform === "win32" ? ".exe" : "");
5471
const subDirName = `${getZigOSName()}-${getZigArchName()}-${version.raw}`;
5572
const exeUri = vscode.Uri.joinPath(config.context.globalStorageUri, config.exeName, subDirName, exeName);

0 commit comments

Comments
 (0)