Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions extensions/ql-vscode/src/databases/database-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fetch, { Response } from "node-fetch";
import { zip } from "zip-a-folder";
import { Open } from "unzipper";
import { Uri, window, InputBoxOptions } from "vscode";
import { CodeQLCliServer } from "../codeql-cli/cli";
import {
Expand Down Expand Up @@ -46,7 +45,7 @@ export async function promptImportInternetDatabase(
databaseManager: DatabaseManager,
storagePath: string,
progress: ProgressCallback,
cli?: CodeQLCliServer,
cli: CodeQLCliServer,
): Promise<DatabaseItem | undefined> {
const databaseUrl = await window.showInputBox({
prompt: "Enter URL of zipfile of database to download",
Expand Down Expand Up @@ -101,7 +100,7 @@ export async function promptImportGithubDatabase(
storagePath: string,
credentials: Credentials | undefined,
progress: ProgressCallback,
cli?: CodeQLCliServer,
cli: CodeQLCliServer,
language?: string,
makeSelected = true,
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
Expand Down Expand Up @@ -180,7 +179,7 @@ export async function downloadGitHubDatabase(
storagePath: string,
credentials: Credentials | undefined,
progress: ProgressCallback,
cli?: CodeQLCliServer,
cli: CodeQLCliServer,
language?: string,
makeSelected = true,
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
Expand Down Expand Up @@ -235,7 +234,7 @@ export async function downloadGitHubDatabaseFromUrl(
progress: ProgressCallback,
databaseManager: DatabaseManager,
storagePath: string,
cli?: CodeQLCliServer,
cli: CodeQLCliServer,
makeSelected = true,
addSourceArchiveFolder = true,
): Promise<DatabaseItem | undefined> {
Expand Down Expand Up @@ -279,14 +278,15 @@ export async function downloadGitHubDatabaseFromUrl(
* @param databaseUrl the file url of the archive to import
* @param databaseManager the DatabaseManager
* @param storagePath where to store the unzipped database.
* @param cli the CodeQL CLI server
*/
export async function importArchiveDatabase(
commandManager: AppCommandManager,
databaseUrl: string,
databaseManager: DatabaseManager,
storagePath: string,
progress: ProgressCallback,
cli?: CodeQLCliServer,
cli: CodeQLCliServer,
): Promise<DatabaseItem | undefined> {
try {
const item = await databaseArchiveFetcher(
Expand Down Expand Up @@ -333,6 +333,7 @@ export async function importArchiveDatabase(
* @param nameOverride a name for the database that overrides the default
* @param origin the origin of the database
* @param progress callback to send progress messages to
* @param cli the CodeQL CLI server
* @param makeSelected make the new database selected in the databases panel (default: true)
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
*/
Expand All @@ -344,7 +345,7 @@ async function databaseArchiveFetcher(
nameOverride: string | undefined,
origin: DatabaseOrigin,
progress: ProgressCallback,
cli?: CodeQLCliServer,
cli: CodeQLCliServer,
makeSelected = true,
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
): Promise<DatabaseItem> {
Expand Down Expand Up @@ -443,34 +444,24 @@ function validateUrl(databaseUrl: string) {
async function readAndUnzip(
zipUrl: string,
unzipPath: string,
cli?: CodeQLCliServer,
cli: CodeQLCliServer,
progress?: ProgressCallback,
) {
// TODO: Providing progress as the file is unzipped is currently blocked
// on https://github.com/ZJONSSON/node-unzipper/issues/222
const zipFile = Uri.parse(zipUrl).fsPath;
progress?.({
maxStep: 10,
step: 9,
message: `Unzipping into ${basename(unzipPath)}`,
});
if (cli) {
// Use the `database unbundle` command if the installed cli version supports it
await cli.databaseUnbundle(zipFile, unzipPath);
} else {
// Must get the zip central directory since streaming the
// zip contents may not have correct local file headers.
// Instead, we can only rely on the central directory.
const directory = await Open.file(zipFile);
await directory.extract({ path: unzipPath });
}

await cli.databaseUnbundle(zipFile, unzipPath);
}

async function fetchAndUnzip(
databaseUrl: string,
requestHeaders: { [key: string]: string },
unzipPath: string,
cli?: CodeQLCliServer,
cli: CodeQLCliServer,
progress?: ProgressCallback,
) {
// Although it is possible to download and stream directly to an unzipped directory,
Expand Down
15 changes: 6 additions & 9 deletions extensions/ql-vscode/src/databases/local-databases-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class DatabaseUI extends DisposableObject {
private app: App,
private databaseManager: DatabaseManager,
languageContext: LanguageContextStore,
private readonly queryServer: QueryRunner | undefined,
private readonly queryServer: QueryRunner,
private readonly storagePath: string,
readonly extensionPath: string,
) {
Expand Down Expand Up @@ -402,10 +402,7 @@ export class DatabaseUI extends DisposableObject {
workspace.workspaceFolders[0].uri.fsPath,
"tutorial-queries",
);
const cli = this.queryServer?.cliServer;
if (!cli) {
throw new Error("No CLI server found");
}
const cli = this.queryServer.cliServer;
await cli.packInstall(tutorialQueriesPath);
}
}
Expand Down Expand Up @@ -528,7 +525,7 @@ export class DatabaseUI extends DisposableObject {
this.databaseManager,
this.storagePath,
progress,
this.queryServer?.cliServer,
this.queryServer.cliServer,
);
},
{
Expand All @@ -548,7 +545,7 @@ export class DatabaseUI extends DisposableObject {
this.storagePath,
credentials,
progress,
this.queryServer?.cliServer,
this.queryServer.cliServer,
);
},
{
Expand Down Expand Up @@ -704,7 +701,7 @@ export class DatabaseUI extends DisposableObject {
this.databaseManager,
this.storagePath,
progress,
this.queryServer?.cliServer,
this.queryServer.cliServer,
);
} else {
await this.databaseManager.openDatabase(uri, {
Expand Down Expand Up @@ -836,7 +833,7 @@ export class DatabaseUI extends DisposableObject {
this.databaseManager,
this.storagePath,
progress,
this.queryServer?.cliServer,
this.queryServer.cliServer,
);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("database-fetcher", () => {

const extension = await getActivatedExtension();
databaseManager = extension.databaseManager;
cli = extension.cliServer;

await cleanDatabases(databaseManager);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describeWithCodeQL()("using the new query server", () => {
// Unlike the old query sevre the new one wants a database and the empty direcrtory is not valid.
const dbItem = await ensureTestDatabase(
extension.databaseManager,
undefined,
cliServer,
);
db = dbItem.databaseUri.fsPath;
});
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/test/vscode-tests/global.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export let storagePath: string;
*/
export async function ensureTestDatabase(
databaseManager: DatabaseManager,
cli: CodeQLCliServer | undefined,
cli: CodeQLCliServer,
): Promise<DatabaseItem> {
// Add a database, but make sure the database manager is empty first
await cleanDatabases(databaseManager);
Expand Down