Merge pull request #170 from jcreedcmu/fix-upgrades
Fix auto-upgrade script path
This commit is contained in:
Коммит
cfcbdcd3d0
|
@ -2,7 +2,7 @@ import * as path from 'path';
|
|||
import { DisposableObject } from "semmle-vscode-utils";
|
||||
import { commands, Event, EventEmitter, ExtensionContext, ProviderResult, TreeDataProvider, TreeItem, Uri, window } from "vscode";
|
||||
import * as cli from './cli';
|
||||
import { DatabaseItem, DatabaseManager } from "./databases";
|
||||
import { DatabaseItem, DatabaseManager, getUpgradesDirectories } from "./databases";
|
||||
import { logger } from "./logging";
|
||||
import { clearCacheInDatabase, upgradeDatabase, UserCancellationException } from "./queries";
|
||||
import * as qsClient from './queryserver-client';
|
||||
|
@ -189,15 +189,10 @@ export class DatabaseUI extends DisposableObject {
|
|||
logger.log('Could not determine target dbscheme to upgrade to.');
|
||||
return;
|
||||
}
|
||||
|
||||
const parentDirs = scripts.map(dir => path.dirname(dir));
|
||||
const uniqueParentDirs = new Set(parentDirs);
|
||||
const targetDbSchemeUri = Uri.file(finalDbscheme);
|
||||
|
||||
|
||||
const upgradesDirectories = Array.from(uniqueParentDirs).map(filePath => Uri.file(filePath));
|
||||
try {
|
||||
await upgradeDatabase(this.queryServer, databaseItem, targetDbSchemeUri, upgradesDirectories);
|
||||
await upgradeDatabase(this.queryServer, databaseItem, targetDbSchemeUri, getUpgradesDirectories(scripts));
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof UserCancellationException) {
|
||||
|
|
|
@ -629,3 +629,13 @@ export class DatabaseManager extends DisposableObject {
|
|||
this.ctx.workspaceState.update(DB_LIST, this._databaseItems.map(item => item.getPersistedState()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of directories containing upgrades, given a list of
|
||||
* scripts returned by the cli's upgrade resolution.
|
||||
*/
|
||||
export function getUpgradesDirectories(scripts: string[]): vscode.Uri[] {
|
||||
const parentDirs = scripts.map(dir => path.dirname(dir));
|
||||
const uniqueParentDirs = new Set(parentDirs);
|
||||
return Array.from(uniqueParentDirs).map(filePath => vscode.Uri.file(filePath));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as sarif from 'sarif';
|
|||
import * as tmp from 'tmp';
|
||||
import * as vscode from 'vscode';
|
||||
import * as cli from './cli';
|
||||
import { DatabaseItem } from './databases';
|
||||
import { DatabaseItem, getUpgradesDirectories } from './databases';
|
||||
import * as helpers from './helpers';
|
||||
import { DatabaseInfo, SortState, ResultsInfo, SortedResultSetInfo } from './interface-types';
|
||||
import { logger } from './logging';
|
||||
|
@ -447,7 +447,7 @@ async function checkDbschemeCompatibility(
|
|||
const searchPath = helpers.getOnDiskWorkspaceFolders();
|
||||
|
||||
if (query.dbItem.contents !== undefined && query.dbItem.contents.dbSchemeUri !== undefined) {
|
||||
const info = await cliServer.resolveUpgrades(query.dbItem.contents.dbSchemeUri.fsPath, searchPath);
|
||||
const { scripts, finalDbscheme } = await cliServer.resolveUpgrades(query.dbItem.contents.dbSchemeUri.fsPath, searchPath);
|
||||
async function hash(filename: string): Promise<string> {
|
||||
return crypto.createHash('sha256').update(await fs.readFile(filename)).digest('hex');
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ async function checkDbschemeCompatibility(
|
|||
const dbschemeOfLib = await hash(query.queryDbscheme);
|
||||
|
||||
// info.finalDbscheme is which database we're able to upgrade to
|
||||
const upgradableTo = await hash(info.finalDbscheme);
|
||||
const upgradableTo = await hash(finalDbscheme);
|
||||
|
||||
if (upgradableTo != dbschemeOfLib) {
|
||||
logger.log(`Query ${query.program.queryPath} expects database scheme ${query.queryDbscheme}, but database has scheme ${query.program.dbschemePath}, and no upgrade path found`);
|
||||
|
@ -476,8 +476,8 @@ async function checkDbschemeCompatibility(
|
|||
await upgradeDatabase(
|
||||
qs,
|
||||
query.dbItem,
|
||||
vscode.Uri.file(info.finalDbscheme),
|
||||
searchPath.map(file => vscode.Uri.file(file))
|
||||
vscode.Uri.file(finalDbscheme),
|
||||
getUpgradesDirectories(scripts)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче