Skip to content

Commit fd3acfb

Browse files
committed
Address pull request comments
1 parent 0ed9242 commit fd3acfb

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ export async function importLocalDatabase(
298298
try {
299299
const origin: DatabaseOrigin = {
300300
type: databaseUrl.endsWith(".testproj") ? "testproj" : "archive",
301-
// TODO validate that archive origins can use a file path, not a URI
302301
path: Uri.parse(databaseUrl).fsPath,
303302
};
304303
const item = await fetchDatabaseToWorkspaceStorage(
@@ -371,7 +370,7 @@ async function fetchDatabaseToWorkspaceStorage(
371370

372371
if (isFile(databaseUrl)) {
373372
if (origin.type === "testproj") {
374-
await copyDatabase(origin.path, unzipPath, progress);
373+
await copyDatabase(databaseUrl, unzipPath, progress);
375374
} else {
376375
await readAndUnzip(databaseUrl, unzipPath, cli, progress);
377376
}
@@ -458,12 +457,12 @@ function validateUrl(databaseUrl: string) {
458457

459458
/**
460459
* Copies a database folder from the file system into the workspace storage.
461-
* @param scrDir the original location of the database
460+
* @param scrDirURL the original location of the database as a URL string
462461
* @param destDir the location to copy the database to. This should be a folder in the workspace storage.
463462
* @param progress callback to send progress messages to
464463
*/
465464
async function copyDatabase(
466-
scrDir: string,
465+
srcDirURL: string,
467466
destDir: string,
468467
progress?: ProgressCallback,
469468
) {
@@ -473,7 +472,7 @@ async function copyDatabase(
473472
message: `Copying database ${basename(destDir)} into the workspace`,
474473
});
475474
await ensureDir(destDir);
476-
await copy(scrDir, destDir);
475+
await copy(Uri.parse(srcDirURL).fsPath, destDir);
477476
}
478477

479478
async function readAndUnzip(

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ export class DatabaseUI extends DisposableObject {
750750
return withProgress(
751751
async (progress) => {
752752
try {
753-
// Assume user has selected an archive if the file has a .zip extension
754753
if (!uri.path.endsWith(".testproj")) {
755754
throw new Error(
756755
"Please select a valid test database to import. Test databases end with `.testproj`.",

extensions/ql-vscode/src/databases/local-databases/database-manager.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,15 @@ export class DatabaseManager extends DisposableObject {
221221
"codeql-database.yml",
222222
);
223223

224-
// TODO add error handling if one does not exist.
225-
const originStat = await stat(originDbYml);
226-
const importedStat = await stat(importedDbYml);
227-
return originStat.mtimeMs > importedStat.mtimeMs;
224+
try {
225+
const originStat = await stat(originDbYml);
226+
const importedStat = await stat(importedDbYml);
227+
return originStat.mtimeMs > importedStat.mtimeMs;
228+
} catch (e) {
229+
// If either of the files does not exist, we assume the origin is newer.
230+
// This shouldn't happen unless the user manually deleted one of the files.
231+
return true;
232+
}
228233
}
229234

230235
/**

extensions/ql-vscode/src/query-server/query-runner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ export interface CoreQueryRun {
6363
export type CoreCompletedQuery = CoreQueryResults &
6464
Omit<CoreQueryRun, "evaluate">;
6565

66-
type OnQueryRunStargingListener = (dbPath: Uri) => Promise<void>;
66+
type OnQueryRunStartingListener = (dbPath: Uri) => Promise<void>;
6767
export class QueryRunner {
6868
constructor(public readonly qs: QueryServerClient) {}
6969

7070
// Event handlers that get notified whenever a query is about to start running.
7171
// Can't use vscode EventEmitters since they are not asynchronous.
72-
private readonly onQueryRunStartingListeners: OnQueryRunStargingListener[] =
72+
private readonly onQueryRunStartingListeners: OnQueryRunStartingListener[] =
7373
[];
74-
public onQueryRunStarting(listener: OnQueryRunStargingListener) {
74+
public onQueryRunStarting(listener: OnQueryRunStartingListener) {
7575
this.onQueryRunStartingListeners.push(listener);
7676
}
7777

extensions/ql-vscode/test/vscode-tests/cli-integration/jest.setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import fetch from "node-fetch";
1212
import { renameSync } from "fs";
1313
import { unzipToDirectoryConcurrently } from "../../../src/common/unzip-concurrently";
1414
import { platform } from "os";
15-
import { wait } from "./utils";
15+
import { sleep } from "../../../src/common/time";
1616

1717
beforeAll(async () => {
1818
// ensure the test database is downloaded
@@ -42,7 +42,7 @@ beforeAll(async () => {
4242
// On Windows, wait a few seconds to make sure all background processes
4343
// release their lock on the files before renaming the directory.
4444
if (platform() === "win32") {
45-
await wait(3000);
45+
await sleep(3000);
4646
}
4747
renameSync(join(dbParentDir, "db"), testprojLoc);
4848
console.log("Unzip completed.");

extensions/ql-vscode/test/vscode-tests/cli-integration/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,3 @@ import { join } from "path";
77
export function getDataFolderFilePath(path: string): string {
88
return join(workspace.workspaceFolders![0].uri.fsPath, path);
99
}
10-
11-
export async function wait(ms = 1000) {
12-
return new Promise((resolve) => setTimeout(resolve, ms));
13-
}

0 commit comments

Comments
 (0)