Download databases into extension storage path

Now that we've figured out how to set the storage path for both Mac &
Windows, we also want to make sure we're consistent with the location
where we save databases.

At the moment, our change will download databases directly in the
workspace folder.

When we call `downloadGitHubDatabase()` in other places outside the
wizard, we provide `ctx.storageUri.fsPath` as the location. [1] [2] [3]

Let's do the same here.

I've tested this on Mac for the codespaces-codeql & starter workspaces.

[1]: c7bb22c312/extensions/ql-vscode/src/local-databases-ui.ts (L476)
[2]: c7bb22c312/extensions/ql-vscode/src/extension.ts (L710)
[3]: c7bb22c312/extensions/ql-vscode/src/extension.ts (L1120)
This commit is contained in:
Elena Tanasoiu
2023-04-12 14:14:32 +00:00
parent 785c8c1f22
commit b4468d612a
4 changed files with 16 additions and 1 deletions

View File

@@ -862,6 +862,7 @@ async function activateWithInstalledDistribution(
databaseUI,
localQueryResultsView,
queryStorageDir,
ctx,
);
ctx.subscriptions.push(localQueries);

View File

@@ -2,6 +2,7 @@ import { ProgressCallback, ProgressUpdate, withProgress } from "./progress";
import {
CancellationToken,
CancellationTokenSource,
ExtensionContext,
QuickPickItem,
Range,
Uri,
@@ -221,6 +222,7 @@ export class LocalQueries extends DisposableObject {
private readonly databaseUI: DatabaseUI,
private readonly localQueryResultsView: ResultsView,
private readonly queryStorageDir: string,
private readonly ctx: ExtensionContext,
) {
super();
}
@@ -381,6 +383,8 @@ export class LocalQueries extends DisposableObject {
await withProgress(
async (progress: ProgressCallback, token: CancellationToken) => {
const credentials = isCanary() ? this.app.credentials : undefined;
const contextStoragePath =
this.ctx.storageUri?.fsPath || this.ctx.globalStorageUri.fsPath;
const skeletonQueryWizard = new SkeletonQueryWizard(
this.cliServer,
progress,
@@ -388,6 +392,7 @@ export class LocalQueries extends DisposableObject {
extLogger,
this.databaseManager,
token,
contextStoragePath,
);
await skeletonQueryWizard.execute();
},

View File

@@ -36,6 +36,7 @@ export class SkeletonQueryWizard {
private readonly extLogger: OutputChannelLogger,
private readonly databaseManager: DatabaseManager,
private readonly token: CancellationToken,
private readonly databaseStoragePath: string | undefined,
) {}
private get folderName() {
@@ -197,6 +198,10 @@ export class SkeletonQueryWizard {
throw new Error("Workspace storage path is undefined");
}
if (this.databaseStoragePath === undefined) {
throw new Error("Database storage path is undefined");
}
if (this.language === undefined) {
throw new Error("Language is undefined");
}
@@ -220,7 +225,7 @@ export class SkeletonQueryWizard {
await databaseFetcher.downloadGitHubDatabase(
chosenRepo,
this.databaseManager,
this.qlPackStoragePath,
this.databaseStoragePath,
this.credentials,
this.progress,
this.token,

View File

@@ -114,6 +114,7 @@ describe("SkeletonQueryWizard", () => {
extLogger,
mockDatabaseManager,
token,
storagePath,
);
askForGitHubRepoSpy = jest
@@ -244,6 +245,7 @@ describe("SkeletonQueryWizard", () => {
extLogger,
mockDatabaseManagerWithItems,
token,
storagePath,
);
});
@@ -317,6 +319,7 @@ describe("SkeletonQueryWizard", () => {
extLogger,
mockDatabaseManager,
token,
storagePath,
);
expect(wizard.getFirstStoragePath()).toEqual("codespaces-codeql");
@@ -352,6 +355,7 @@ describe("SkeletonQueryWizard", () => {
extLogger,
mockDatabaseManager,
token,
storagePath,
);
expect(wizard.getFirstStoragePath()).toEqual("vscode-codeql-starter");