Skip to content

Commit 8ed7b99

Browse files
committed
fix: Avoid auto-updating the codeql binaries
On startup, if a new binary is available, request user acceptance before starting the update. Fixes #283
1 parent deb544a commit 8ed7b99

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Add new command in query history view to view the log file of a
66
query.
7+
- Avoid updating the CodeQL binaries without user acknowledgment.
78

89
## 1.1.0 - 17 March 2020
910

extensions/ql-vscode/src/extension.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
9393
interface DistributionUpdateConfig {
9494
isUserInitiated: boolean;
9595
shouldDisplayMessageWhenNoUpdates: boolean;
96+
avoidAutoUpdating: boolean;
9697
}
9798

9899
async function installOrUpdateDistributionWithProgressTitle(progressTitle: string, config: DistributionUpdateConfig): Promise<void> {
@@ -112,7 +113,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
112113
await noUpdatesLoggingFunc("CodeQL CLI is installed externally so could not be updated.");
113114
break;
114115
case DistributionUpdateCheckResultKind.UpdateAvailable:
115-
if (beganMainExtensionActivation) {
116+
if (beganMainExtensionActivation || config.avoidAutoUpdating) {
116117
const updateAvailableMessage = `Version "${result.updatedRelease.name}" of the CodeQL CLI is now available. ` +
117118
"The update will be installed after Visual Studio Code restarts. Restart now to upgrade?";
118119
await ctx.globalState.update(shouldUpdateOnNextActivationKey, true);
@@ -144,8 +145,12 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
144145
isInstallingOrUpdatingDistribution = true;
145146
const codeQlInstalled = await distributionManager.getCodeQlPathWithoutVersionCheck() !== undefined;
146147
const willUpdateCodeQl = ctx.globalState.get(shouldUpdateOnNextActivationKey);
147-
const messageText = willUpdateCodeQl ? "Updating CodeQL CLI" :
148-
codeQlInstalled ? "Checking for updates to CodeQL CLI" : "Installing CodeQL CLI";
148+
const messageText = willUpdateCodeQl
149+
? "Updating CodeQL CLI"
150+
: codeQlInstalled
151+
? "Checking for updates to CodeQL CLI"
152+
: "Installing CodeQL CLI";
153+
149154
try {
150155
await installOrUpdateDistributionWithProgressTitle(messageText, config);
151156
} catch (e) {
@@ -207,7 +212,8 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
207212
if (chosenAction === installActionName) {
208213
installOrUpdateThenTryActivate({
209214
isUserInitiated: true,
210-
shouldDisplayMessageWhenNoUpdates: false
215+
shouldDisplayMessageWhenNoUpdates: false,
216+
avoidAutoUpdating: false
211217
});
212218
}
213219
});
@@ -216,16 +222,22 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
216222

217223
ctx.subscriptions.push(distributionConfigListener.onDidChangeDistributionConfiguration(() => installOrUpdateThenTryActivate({
218224
isUserInitiated: true,
219-
shouldDisplayMessageWhenNoUpdates: false
225+
shouldDisplayMessageWhenNoUpdates: false,
226+
227+
// only auto update on startup if the user has previously requested an update
228+
// otherwise, ask user to accept the update
229+
avoidAutoUpdating: !!ctx.globalState.get(shouldUpdateOnNextActivationKey)
220230
})));
221231
ctx.subscriptions.push(commands.registerCommand(checkForUpdatesCommand, () => installOrUpdateThenTryActivate({
222232
isUserInitiated: true,
223-
shouldDisplayMessageWhenNoUpdates: true
233+
shouldDisplayMessageWhenNoUpdates: true,
234+
avoidAutoUpdating: false
224235
})));
225236

226237
await installOrUpdateThenTryActivate({
227238
isUserInitiated: !!ctx.globalState.get(shouldUpdateOnNextActivationKey),
228-
shouldDisplayMessageWhenNoUpdates: false
239+
shouldDisplayMessageWhenNoUpdates: false,
240+
avoidAutoUpdating: true
229241
});
230242
}
231243

0 commit comments

Comments
 (0)