Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for (de-)registering databases with the query server #681

Merged
merged 4 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [UNRELEASED]

- Ensure databases are unlocked when removing them from the workspace. This will ensure that queries can be run on a database from the command line after being removed. Requires CodeQL CLI 2.4.1 or later. [#681](https://github.com/github/vscode-codeql/pull/681)
adityasharad marked this conversation as resolved.
Show resolved Hide resolved
- Fix bug when removing databases where sometimes the source folder would not be removed from the workspace or the database files would not be removed from the workspace storage location. [#692](https://github.com/github/vscode-codeql/pull/692)

## 1.3.7 - 24 November 2020
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class CodeQLCliServer implements Disposable {
nullBuffer: Buffer;

/** Version of current cli, lazily computed by the `getVersion()` method */
_version: SemVer | undefined;
private _version: SemVer | undefined;

/** Path to current codeQL executable, or undefined if not running yet. */
codeQlPath: string | undefined;
Expand Down Expand Up @@ -699,7 +699,7 @@ export class CodeQLCliServer implements Disposable {
);
}

private async getVersion() {
public async getVersion() {
if (!this._version) {
this._version = await this.refreshVersion();
}
Expand Down
31 changes: 18 additions & 13 deletions extensions/ql-vscode/src/databaseFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function promptImportInternetDatabase(
databasesManager: DatabaseManager,
storagePath: string,
progress: ProgressCallback,
_: CancellationToken,
token: CancellationToken,
): Promise<DatabaseItem | undefined> {
const databaseUrl = await window.showInputBox({
prompt: 'Enter URL of zipfile of database to download',
Expand All @@ -42,7 +42,8 @@ export async function promptImportInternetDatabase(
databaseUrl,
databasesManager,
storagePath,
progress
progress,
token
);

if (item) {
Expand All @@ -65,7 +66,7 @@ export async function promptImportLgtmDatabase(
databasesManager: DatabaseManager,
storagePath: string,
progress: ProgressCallback,
_: CancellationToken
token: CancellationToken
): Promise<DatabaseItem | undefined> {
const lgtmUrl = await window.showInputBox({
prompt:
Expand All @@ -82,7 +83,8 @@ export async function promptImportLgtmDatabase(
databaseUrl,
databasesManager,
storagePath,
progress
progress,
token
);
if (item) {
commands.executeCommand('codeQLDatabases.focus');
Expand All @@ -108,14 +110,15 @@ export async function importArchiveDatabase(
databasesManager: DatabaseManager,
storagePath: string,
progress: ProgressCallback,
_: CancellationToken,
token: CancellationToken,
): Promise<DatabaseItem | undefined> {
try {
const item = await databaseArchiveFetcher(
databaseUrl,
databasesManager,
storagePath,
progress
progress,
token
);
if (item) {
commands.executeCommand('codeQLDatabases.focus');
Expand All @@ -139,15 +142,17 @@ export async function importArchiveDatabase(
* @param databaseUrl URL from which to grab the database
* @param databasesManager the DatabaseManager
* @param storagePath where to store the unzipped database.
* @param progressCallback optional callback to send progress messages to
* @param progress callback to send progress messages to
* @param token cancellation token
*/
async function databaseArchiveFetcher(
databaseUrl: string,
databasesManager: DatabaseManager,
storagePath: string,
progressCallback?: ProgressCallback
progress: ProgressCallback,
token: CancellationToken
): Promise<DatabaseItem> {
progressCallback?.({
progress({
message: 'Getting database',
step: 1,
maxStep: 4,
Expand All @@ -161,10 +166,10 @@ async function databaseArchiveFetcher(
if (isFile(databaseUrl)) {
await readAndUnzip(databaseUrl, unzipPath);
} else {
await fetchAndUnzip(databaseUrl, unzipPath, progressCallback);
await fetchAndUnzip(databaseUrl, unzipPath, progress);
}

progressCallback?.({
progress({
message: 'Opening database',
step: 3,
maxStep: 4,
Expand All @@ -177,14 +182,14 @@ async function databaseArchiveFetcher(
'codeql-database.yml'
);
if (dbPath) {
progressCallback?.({
progress({
message: 'Validating and fixing source location',
step: 4,
maxStep: 4,
});
await ensureZippedSourceLocation(dbPath);

const item = await databasesManager.openDatabase(Uri.file(dbPath));
const item = await databasesManager.openDatabase(progress, token, Uri.file(dbPath));
databasesManager.setCurrentDatabaseItem(item);
return item;
} else {
Expand Down
26 changes: 17 additions & 9 deletions extensions/ql-vscode/src/databases-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,13 @@ export class DatabaseUI extends DisposableObject {
)
);
this.push(
commandRunner(
commandRunnerWithProgress(
'codeQLDatabases.removeDatabase',
this.handleRemoveDatabase
this.handleRemoveDatabase,
{
title: 'Removing database',
cancellable: false
}
)
);
this.push(
Expand Down Expand Up @@ -580,7 +584,7 @@ export class DatabaseUI extends DisposableObject {
token
);
} else {
await this.setCurrentDatabase(uri);
await this.setCurrentDatabase(progress, token, uri);
}
} catch (e) {
// rethrow and let this be handled by default error handling.
Expand All @@ -593,15 +597,17 @@ export class DatabaseUI extends DisposableObject {
};

private handleRemoveDatabase = async (
progress: ProgressCallback,
token: CancellationToken,
databaseItem: DatabaseItem,
multiSelect: DatabaseItem[] | undefined
): Promise<void> => {
if (multiSelect?.length) {
multiSelect.forEach((dbItem) =>
this.databaseManager.removeDatabaseItem(dbItem)
);
Promise.all(multiSelect.map((dbItem) =>
adityasharad marked this conversation as resolved.
Show resolved Hide resolved
this.databaseManager.removeDatabaseItem(progress, token, dbItem)
));
} else {
this.databaseManager.removeDatabaseItem(databaseItem);
await this.databaseManager.removeDatabaseItem(progress, token, databaseItem);
}
};

Expand Down Expand Up @@ -651,11 +657,13 @@ export class DatabaseUI extends DisposableObject {
}

private async setCurrentDatabase(
progress: ProgressCallback,
token: CancellationToken,
uri: Uri
): Promise<DatabaseItem | undefined> {
let databaseItem = this.databaseManager.findDatabaseItem(uri);
if (databaseItem === undefined) {
databaseItem = await this.databaseManager.openDatabase(uri);
databaseItem = await this.databaseManager.openDatabase(progress, token, uri);
}
await this.databaseManager.setCurrentDatabaseItem(databaseItem);

Expand All @@ -680,7 +688,7 @@ export class DatabaseUI extends DisposableObject {
if (byFolder) {
const fixedUri = await this.fixDbUri(uri);
// we are selecting a database folder
return await this.setCurrentDatabase(fixedUri);
return await this.setCurrentDatabase(progress, token, fixedUri);
} else {
// we are selecting a database archive. Must unzip into a workspace-controlled area
// before importing.
Expand Down
Loading