Merge pull request #170 from jcreedcmu/fix-upgrades

Fix auto-upgrade script path
This commit is contained in:
Aditya Sharad 2019-11-18 13:08:27 -08:00 коммит произвёл GitHub
Родитель 1dffeb97d3 a1f0af9086
Коммит cfcbdcd3d0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 21 добавлений и 16 удалений

Просмотреть файл

@ -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';
@ -388,18 +388,18 @@ export async function clearCacheInDatabase(qs: qsClient.QueryServerClient, dbIte
title: "Clearing Cache",
cancellable: false,
}, (progress, token) =>
qs.sendRequest(messages.clearCache, params, token, progress)
qs.sendRequest(messages.clearCache, params, token, progress)
);
}
/**
*
*
* @param filePath This needs to be equivalent to java Path.toRealPath(NO_FOLLOW_LINKS)
*
*
*/
async function convertToQlPath(filePath: string): Promise<string> {
if (process.platform === "win32") {
if (path.parse(filePath).root === filePath) {
// Java assumes uppercase drive letters are canonical.
return filePath.toUpperCase();
@ -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)
);
}
}