Ensure src.zip is prioritized over src folder
Fixes a bug where legacy databases with both unzipped and zipped sources were incorrectly being loaded with the src folder.
This commit is contained in:
@@ -121,20 +121,21 @@ async function findDataset(parentDirectory: string): Promise<vscode.Uri> {
|
||||
return vscode.Uri.file(dbAbsolutePath);
|
||||
}
|
||||
|
||||
async function findSourceArchive(
|
||||
// exported for testing
|
||||
export async function findSourceArchive(
|
||||
databasePath: string, silent = false
|
||||
): Promise<vscode.Uri | undefined> {
|
||||
|
||||
const relativePaths = ['src', 'output/src_archive'];
|
||||
|
||||
for (const relativePath of relativePaths) {
|
||||
const basePath = path.join(databasePath, relativePath);
|
||||
const zipPath = basePath + '.zip';
|
||||
|
||||
if (await fs.pathExists(basePath)) {
|
||||
return vscode.Uri.file(basePath);
|
||||
} else if (await fs.pathExists(zipPath)) {
|
||||
// Prefer using a zip archive over a directory.
|
||||
if (await fs.pathExists(zipPath)) {
|
||||
return encodeArchiveBasePath(zipPath);
|
||||
} else if (await fs.pathExists(basePath)) {
|
||||
return vscode.Uri.file(basePath);
|
||||
}
|
||||
}
|
||||
if (!silent) {
|
||||
@@ -161,7 +162,6 @@ async function resolveDatabase(
|
||||
datasetUri,
|
||||
sourceArchiveUri
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/** Gets the relative paths of all `.dbscheme` files in the given directory. */
|
||||
|
||||
@@ -12,7 +12,8 @@ import {
|
||||
DatabaseManager,
|
||||
DatabaseItemImpl,
|
||||
DatabaseContents,
|
||||
FullDatabaseOptions
|
||||
FullDatabaseOptions,
|
||||
findSourceArchive
|
||||
} from '../../databases';
|
||||
import { Logger } from '../../logging';
|
||||
import { QueryServerClient } from '../../queryserver-client';
|
||||
@@ -179,7 +180,7 @@ describe('databases', () => {
|
||||
expect(spy).to.have.been.calledWith(mockEvent);
|
||||
});
|
||||
|
||||
it('should add a database item source archive', async function () {
|
||||
it('should add a database item source archive', async function() {
|
||||
const mockDbItem = createMockDB();
|
||||
mockDbItem.name = 'xxx';
|
||||
await (databaseManager as any).addDatabaseSourceArchiveFolder(mockDbItem);
|
||||
@@ -478,6 +479,49 @@ describe('databases', () => {
|
||||
const db = createMockDB(sourceLocationUri(), Uri.file('/path/to/dir/dir.testproj'));
|
||||
expect(await db.isAffectedByTest('/path/to/test.ql')).to.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe.only('findSourceArchive', function() {
|
||||
// not sure why, but some of these tests take more than two second to run.
|
||||
this.timeout(5000);
|
||||
|
||||
['src', 'output/src_archive'].forEach(name => {
|
||||
it(`should find source folder in ${name}`, async () => {
|
||||
const uri = Uri.file(path.join(dir.name, name));
|
||||
fs.createFileSync(path.join(uri.fsPath, 'hucairz.txt'));
|
||||
const srcUri = await findSourceArchive(dir.name);
|
||||
expect(srcUri!.fsPath).to.eq(uri.fsPath);
|
||||
});
|
||||
|
||||
it(`should find source archive in ${name}.zip`, async () => {
|
||||
const uri = Uri.file(path.join(dir.name, name + '.zip'));
|
||||
fs.createFileSync(uri.fsPath);
|
||||
const srcUri = await findSourceArchive(dir.name);
|
||||
expect(srcUri!.fsPath).to.eq(uri.fsPath);
|
||||
});
|
||||
|
||||
it(`should prioritize ${name}.zip over ${name}`, async () => {
|
||||
const uri = Uri.file(path.join(dir.name, name + '.zip'));
|
||||
fs.createFileSync(uri.fsPath);
|
||||
|
||||
const uriFolder = Uri.file(path.join(dir.name, name));
|
||||
fs.createFileSync(path.join(uriFolder.fsPath, 'hucairz.txt'));
|
||||
|
||||
const srcUri = await findSourceArchive(dir.name);
|
||||
expect(srcUri!.fsPath).to.eq(uri.fsPath);
|
||||
});
|
||||
});
|
||||
|
||||
it('should prioritize src over output/src_archive', async () => {
|
||||
const uriSrc = Uri.file(path.join(dir.name, 'src.zip'));
|
||||
fs.createFileSync(uriSrc.fsPath);
|
||||
const uriSrcArchive = Uri.file(path.join(dir.name, 'src.zip'));
|
||||
fs.createFileSync(uriSrcArchive.fsPath);
|
||||
|
||||
const resultUri = await findSourceArchive(dir.name);
|
||||
expect(resultUri!.fsPath).to.eq(uriSrc.fsPath);
|
||||
});
|
||||
});
|
||||
|
||||
function createMockDB(
|
||||
|
||||
Reference in New Issue
Block a user