Skip to content

Commit 14b2282

Browse files
committed
Remove fallback behavior for database unbundle
The CodeQL CLI always supports the `database unbundle` command since 140d369 so we can remove the fallback behavior. There were some places which were not passing in the CodeQL CLI server, but these always have access to the CLI server, so this just passes them in. The only change in behavior (in terms of the fallback behavior) is in the `new-query.test.ts` test.
1 parent 6cfa0a9 commit 14b2282

File tree

5 files changed

+21
-32
lines changed

5 files changed

+21
-32
lines changed

extensions/ql-vscode/src/databases/database-fetcher.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fetch, { Response } from "node-fetch";
22
import { zip } from "zip-a-folder";
3-
import { Open } from "unzipper";
43
import { Uri, window, InputBoxOptions } from "vscode";
54
import { CodeQLCliServer } from "../codeql-cli/cli";
65
import {
@@ -46,7 +45,7 @@ export async function promptImportInternetDatabase(
4645
databaseManager: DatabaseManager,
4746
storagePath: string,
4847
progress: ProgressCallback,
49-
cli?: CodeQLCliServer,
48+
cli: CodeQLCliServer,
5049
): Promise<DatabaseItem | undefined> {
5150
const databaseUrl = await window.showInputBox({
5251
prompt: "Enter URL of zipfile of database to download",
@@ -101,7 +100,7 @@ export async function promptImportGithubDatabase(
101100
storagePath: string,
102101
credentials: Credentials | undefined,
103102
progress: ProgressCallback,
104-
cli?: CodeQLCliServer,
103+
cli: CodeQLCliServer,
105104
language?: string,
106105
makeSelected = true,
107106
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
@@ -180,7 +179,7 @@ export async function downloadGitHubDatabase(
180179
storagePath: string,
181180
credentials: Credentials | undefined,
182181
progress: ProgressCallback,
183-
cli?: CodeQLCliServer,
182+
cli: CodeQLCliServer,
184183
language?: string,
185184
makeSelected = true,
186185
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
@@ -235,7 +234,7 @@ export async function downloadGitHubDatabaseFromUrl(
235234
progress: ProgressCallback,
236235
databaseManager: DatabaseManager,
237236
storagePath: string,
238-
cli?: CodeQLCliServer,
237+
cli: CodeQLCliServer,
239238
makeSelected = true,
240239
addSourceArchiveFolder = true,
241240
): Promise<DatabaseItem | undefined> {
@@ -279,14 +278,15 @@ export async function downloadGitHubDatabaseFromUrl(
279278
* @param databaseUrl the file url of the archive to import
280279
* @param databaseManager the DatabaseManager
281280
* @param storagePath where to store the unzipped database.
281+
* @param cli the CodeQL CLI server
282282
*/
283283
export async function importArchiveDatabase(
284284
commandManager: AppCommandManager,
285285
databaseUrl: string,
286286
databaseManager: DatabaseManager,
287287
storagePath: string,
288288
progress: ProgressCallback,
289-
cli?: CodeQLCliServer,
289+
cli: CodeQLCliServer,
290290
): Promise<DatabaseItem | undefined> {
291291
try {
292292
const item = await databaseArchiveFetcher(
@@ -333,6 +333,7 @@ export async function importArchiveDatabase(
333333
* @param nameOverride a name for the database that overrides the default
334334
* @param origin the origin of the database
335335
* @param progress callback to send progress messages to
336+
* @param cli the CodeQL CLI server
336337
* @param makeSelected make the new database selected in the databases panel (default: true)
337338
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
338339
*/
@@ -344,7 +345,7 @@ async function databaseArchiveFetcher(
344345
nameOverride: string | undefined,
345346
origin: DatabaseOrigin,
346347
progress: ProgressCallback,
347-
cli?: CodeQLCliServer,
348+
cli: CodeQLCliServer,
348349
makeSelected = true,
349350
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
350351
): Promise<DatabaseItem> {
@@ -443,34 +444,24 @@ function validateUrl(databaseUrl: string) {
443444
async function readAndUnzip(
444445
zipUrl: string,
445446
unzipPath: string,
446-
cli?: CodeQLCliServer,
447+
cli: CodeQLCliServer,
447448
progress?: ProgressCallback,
448449
) {
449-
// TODO: Providing progress as the file is unzipped is currently blocked
450-
// on https://github.com/ZJONSSON/node-unzipper/issues/222
451450
const zipFile = Uri.parse(zipUrl).fsPath;
452451
progress?.({
453452
maxStep: 10,
454453
step: 9,
455454
message: `Unzipping into ${basename(unzipPath)}`,
456455
});
457-
if (cli) {
458-
// Use the `database unbundle` command if the installed cli version supports it
459-
await cli.databaseUnbundle(zipFile, unzipPath);
460-
} else {
461-
// Must get the zip central directory since streaming the
462-
// zip contents may not have correct local file headers.
463-
// Instead, we can only rely on the central directory.
464-
const directory = await Open.file(zipFile);
465-
await directory.extract({ path: unzipPath });
466-
}
456+
457+
await cli.databaseUnbundle(zipFile, unzipPath);
467458
}
468459

469460
async function fetchAndUnzip(
470461
databaseUrl: string,
471462
requestHeaders: { [key: string]: string },
472463
unzipPath: string,
473-
cli?: CodeQLCliServer,
464+
cli: CodeQLCliServer,
474465
progress?: ProgressCallback,
475466
) {
476467
// Although it is possible to download and stream directly to an unzipped directory,

extensions/ql-vscode/src/databases/local-databases-ui.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class DatabaseUI extends DisposableObject {
233233
private app: App,
234234
private databaseManager: DatabaseManager,
235235
languageContext: LanguageContextStore,
236-
private readonly queryServer: QueryRunner | undefined,
236+
private readonly queryServer: QueryRunner,
237237
private readonly storagePath: string,
238238
readonly extensionPath: string,
239239
) {
@@ -402,10 +402,7 @@ export class DatabaseUI extends DisposableObject {
402402
workspace.workspaceFolders[0].uri.fsPath,
403403
"tutorial-queries",
404404
);
405-
const cli = this.queryServer?.cliServer;
406-
if (!cli) {
407-
throw new Error("No CLI server found");
408-
}
405+
const cli = this.queryServer.cliServer;
409406
await cli.packInstall(tutorialQueriesPath);
410407
}
411408
}
@@ -528,7 +525,7 @@ export class DatabaseUI extends DisposableObject {
528525
this.databaseManager,
529526
this.storagePath,
530527
progress,
531-
this.queryServer?.cliServer,
528+
this.queryServer.cliServer,
532529
);
533530
},
534531
{
@@ -548,7 +545,7 @@ export class DatabaseUI extends DisposableObject {
548545
this.storagePath,
549546
credentials,
550547
progress,
551-
this.queryServer?.cliServer,
548+
this.queryServer.cliServer,
552549
);
553550
},
554551
{
@@ -704,7 +701,7 @@ export class DatabaseUI extends DisposableObject {
704701
this.databaseManager,
705702
this.storagePath,
706703
progress,
707-
this.queryServer?.cliServer,
704+
this.queryServer.cliServer,
708705
);
709706
} else {
710707
await this.databaseManager.openDatabase(uri, {
@@ -836,7 +833,7 @@ export class DatabaseUI extends DisposableObject {
836833
this.databaseManager,
837834
this.storagePath,
838835
progress,
839-
this.queryServer?.cliServer,
836+
this.queryServer.cliServer,
840837
);
841838
}
842839
},

extensions/ql-vscode/test/vscode-tests/cli-integration/databases/database-fetcher.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe("database-fetcher", () => {
3636

3737
const extension = await getActivatedExtension();
3838
databaseManager = extension.databaseManager;
39+
cli = extension.cliServer;
3940

4041
await cleanDatabases(databaseManager);
4142
});

extensions/ql-vscode/test/vscode-tests/cli-integration/new-query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describeWithCodeQL()("using the new query server", () => {
135135
// Unlike the old query sevre the new one wants a database and the empty direcrtory is not valid.
136136
const dbItem = await ensureTestDatabase(
137137
extension.databaseManager,
138-
undefined,
138+
cliServer,
139139
);
140140
db = dbItem.databaseUri.fsPath;
141141
});

extensions/ql-vscode/test/vscode-tests/global.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export let storagePath: string;
2828
*/
2929
export async function ensureTestDatabase(
3030
databaseManager: DatabaseManager,
31-
cli: CodeQLCliServer | undefined,
31+
cli: CodeQLCliServer,
3232
): Promise<DatabaseItem> {
3333
// Add a database, but make sure the database manager is empty first
3434
await cleanDatabases(databaseManager);

0 commit comments

Comments
 (0)