Merge pull request #3486 from github/aeisenberg/ignore-missing-database

Three minor improvements to `testproj` import
This commit is contained in:
Andrew Eisenberg
2024-03-18 12:47:43 -07:00
committed by GitHub
3 changed files with 17 additions and 4 deletions

View File

@@ -666,7 +666,9 @@ function isFile(databaseUrl: string) {
*
* @param databasePath The full path to the unzipped database
*/
async function ensureZippedSourceLocation(databasePath: string): Promise<void> {
export async function ensureZippedSourceLocation(
databasePath: string,
): Promise<void> {
const srcFolderPath = join(databasePath, "src");
const srcZipPath = `${srcFolderPath}.zip`;

View File

@@ -995,14 +995,15 @@ export class DatabaseUI extends DisposableObject {
return undefined;
}
if (byFolder) {
if (byFolder && !uri.fsPath.endsWith("testproj")) {
const fixedUri = await this.fixDbUri(uri);
// we are selecting a database folder
return await this.databaseManager.openDatabase(fixedUri, {
type: "folder",
});
} else {
// we are selecting a database archive. Must unzip into a workspace-controlled area
// we are selecting a database archive or a testproj.
// Unzip archives (if an archive) and copy into a workspace-controlled area
// before importing.
return await importLocalDatabase(
this.app.commands,

View File

@@ -43,6 +43,7 @@ import { DatabaseResolver } from "./database-resolver";
import { telemetryListener } from "../../common/vscode/telemetry";
import type { LanguageContextStore } from "../../language-context-store";
import type { DatabaseOrigin } from "./database-origin";
import { ensureZippedSourceLocation } from "../database-fetcher";
/**
* The name of the key in the workspaceState dictionary in which we
@@ -227,8 +228,16 @@ export class DatabaseManager extends DisposableObject {
"codeql-database.yml",
);
let originStat;
try {
originStat = await stat(originDbYml);
} catch (e) {
// if there is an error here, assume that the origin database
// is no longer available. Safely ignore and do not try to re-import.
return false;
}
try {
const originStat = await stat(originDbYml);
const importedStat = await stat(importedDbYml);
return originStat.mtimeMs > importedStat.mtimeMs;
} catch (e) {
@@ -252,6 +261,7 @@ export class DatabaseManager extends DisposableObject {
await this.removeDatabaseItem(dbItem);
await copy(dbItem.origin.path, databaseUri.fsPath);
await ensureZippedSourceLocation(databaseUri.fsPath);
const newDbItem = new DatabaseItemImpl(databaseUri, dbItem.contents, {
dateAdded: Date.now(),
language: dbItem.language,