Remove ignoreSourceArchive option from databases

This option was used to ignore source archives for `.testproj`
databases. It is only set to `true` or `false` when creating the
database and could not be changed, so I don't think we need this option.
It can simply be derived from the database URI. This simplifies handling
of databases a bit.
This commit is contained in:
Koen Vlaswinkel
2023-06-01 15:32:30 +02:00
parent 2f61cfe693
commit 0e47709d10
5 changed files with 8 additions and 15 deletions

View File

@@ -2,7 +2,7 @@
import * as cli from "../../codeql-cli/cli";
import vscode from "vscode";
import { FullDatabaseOptions } from "./database-options";
import { basename, dirname, join, relative } from "path";
import { basename, dirname, extname, join, relative } from "path";
import {
decodeSourceArchiveUri,
encodeArchiveBasePath,
@@ -45,13 +45,18 @@ export class DatabaseItemImpl implements DatabaseItem {
}
public get sourceArchive(): vscode.Uri | undefined {
if (this.options.ignoreSourceArchive || this.contents === undefined) {
if (this.ignoreSourceArchive || this.contents === undefined) {
return undefined;
} else {
return this.contents.sourceArchiveUri;
}
}
private get ignoreSourceArchive(): boolean {
// Ignore the source archive for QLTest databases.
return extname(this.databaseUri.fsPath) === ".testproj";
}
public get dateAdded(): number | undefined {
return this.options.dateAdded;
}

View File

@@ -10,7 +10,7 @@ import {
isCodespacesTemplate,
setAutogenerateQlPacks,
} from "../../config";
import { extname, join } from "path";
import { join } from "path";
import { FullDatabaseOptions } from "./database-options";
import { DatabaseItemImpl } from "./database-item-impl";
import {
@@ -164,10 +164,7 @@ export class DatabaseManager extends DisposableObject {
displayName: string | undefined,
): Promise<DatabaseItemImpl> {
const contents = await DatabaseResolver.resolveDatabaseContents(uri);
// Ignore the source archive for QLTest databases by default.
const isQLTestDatabase = extname(uri.fsPath) === ".testproj";
const fullOptions: FullDatabaseOptions = {
ignoreSourceArchive: isQLTestDatabase,
// If a displayName is not passed in, the basename of folder containing the database is used.
displayName,
dateAdded: Date.now(),
@@ -324,16 +321,12 @@ export class DatabaseManager extends DisposableObject {
state: PersistedDatabaseItem,
): Promise<DatabaseItemImpl> {
let displayName: string | undefined = undefined;
let ignoreSourceArchive = false;
let dateAdded = undefined;
let language = undefined;
if (state.options) {
if (typeof state.options.displayName === "string") {
displayName = state.options.displayName;
}
if (typeof state.options.ignoreSourceArchive === "boolean") {
ignoreSourceArchive = state.options.ignoreSourceArchive;
}
if (typeof state.options.dateAdded === "number") {
dateAdded = state.options.dateAdded;
}
@@ -347,7 +340,6 @@ export class DatabaseManager extends DisposableObject {
}
const fullOptions: FullDatabaseOptions = {
ignoreSourceArchive,
displayName,
dateAdded,
language,

View File

@@ -1,12 +1,10 @@
export interface DatabaseOptions {
displayName?: string;
ignoreSourceArchive?: boolean;
dateAdded?: number | undefined;
language?: string;
}
export interface FullDatabaseOptions extends DatabaseOptions {
ignoreSourceArchive: boolean;
dateAdded: number | undefined;
language: string | undefined;
}

View File

@@ -10,7 +10,6 @@ import { DirResult } from "tmp";
export function mockDbOptions(): FullDatabaseOptions {
return {
dateAdded: 123,
ignoreSourceArchive: false,
language: "",
};
}

View File

@@ -634,7 +634,6 @@ describe("local databases", () => {
const options: FullDatabaseOptions = {
dateAdded: 123,
ignoreSourceArchive: false,
language,
};
mockDbItem = createMockDB(dir, options);