fix: Avoid auto-updating the codeql binaries

On startup, if a new binary is available, request user acceptance
before starting the update.

Fixes #283
This commit is contained in:
Andrew Eisenberg
2020-03-18 11:43:58 -07:00
parent deb544ab93
commit 8ed7b991be
2 changed files with 20 additions and 7 deletions

View File

@@ -4,6 +4,7 @@
- Add new command in query history view to view the log file of a
query.
- Avoid updating the CodeQL binaries without user acknowledgment.
## 1.1.0 - 17 March 2020

View File

@@ -93,6 +93,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
interface DistributionUpdateConfig {
isUserInitiated: boolean;
shouldDisplayMessageWhenNoUpdates: boolean;
avoidAutoUpdating: boolean;
}
async function installOrUpdateDistributionWithProgressTitle(progressTitle: string, config: DistributionUpdateConfig): Promise<void> {
@@ -112,7 +113,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
await noUpdatesLoggingFunc("CodeQL CLI is installed externally so could not be updated.");
break;
case DistributionUpdateCheckResultKind.UpdateAvailable:
if (beganMainExtensionActivation) {
if (beganMainExtensionActivation || config.avoidAutoUpdating) {
const updateAvailableMessage = `Version "${result.updatedRelease.name}" of the CodeQL CLI is now available. ` +
"The update will be installed after Visual Studio Code restarts. Restart now to upgrade?";
await ctx.globalState.update(shouldUpdateOnNextActivationKey, true);
@@ -144,8 +145,12 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
isInstallingOrUpdatingDistribution = true;
const codeQlInstalled = await distributionManager.getCodeQlPathWithoutVersionCheck() !== undefined;
const willUpdateCodeQl = ctx.globalState.get(shouldUpdateOnNextActivationKey);
const messageText = willUpdateCodeQl ? "Updating CodeQL CLI" :
codeQlInstalled ? "Checking for updates to CodeQL CLI" : "Installing CodeQL CLI";
const messageText = willUpdateCodeQl
? "Updating CodeQL CLI"
: codeQlInstalled
? "Checking for updates to CodeQL CLI"
: "Installing CodeQL CLI";
try {
await installOrUpdateDistributionWithProgressTitle(messageText, config);
} catch (e) {
@@ -207,7 +212,8 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
if (chosenAction === installActionName) {
installOrUpdateThenTryActivate({
isUserInitiated: true,
shouldDisplayMessageWhenNoUpdates: false
shouldDisplayMessageWhenNoUpdates: false,
avoidAutoUpdating: false
});
}
});
@@ -216,16 +222,22 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
ctx.subscriptions.push(distributionConfigListener.onDidChangeDistributionConfiguration(() => installOrUpdateThenTryActivate({
isUserInitiated: true,
shouldDisplayMessageWhenNoUpdates: false
shouldDisplayMessageWhenNoUpdates: false,
// only auto update on startup if the user has previously requested an update
// otherwise, ask user to accept the update
avoidAutoUpdating: !!ctx.globalState.get(shouldUpdateOnNextActivationKey)
})));
ctx.subscriptions.push(commands.registerCommand(checkForUpdatesCommand, () => installOrUpdateThenTryActivate({
isUserInitiated: true,
shouldDisplayMessageWhenNoUpdates: true
shouldDisplayMessageWhenNoUpdates: true,
avoidAutoUpdating: false
})));
await installOrUpdateThenTryActivate({
isUserInitiated: !!ctx.globalState.get(shouldUpdateOnNextActivationKey),
shouldDisplayMessageWhenNoUpdates: false
shouldDisplayMessageWhenNoUpdates: false,
avoidAutoUpdating: true
});
}