Skip to content

Commit b32d0e5

Browse files
Add version check to new feature
Co-authored by: Marc Jaramillo mnj.webdeveloper@gmail.com Co-authored by: Musab Guma'a mgsium@github.com
1 parent 863d69c commit b32d0e5

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

extensions/ql-vscode/src/cli.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,11 @@ export class CliVersionConstraint {
10831083
*/
10841084
public static CLI_VERSION_WITH_ALLOW_LIBRARY_PACKS_IN_RESOLVE_QUERIES = new SemVer('2.6.1');
10851085

1086+
/**
1087+
* CLI version where the `database unbundle` subcommand was introduced.
1088+
*/
1089+
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer('2.6.4');
1090+
10861091
constructor(private readonly cli: CodeQLCliServer) {
10871092
/**/
10881093
}
@@ -1114,4 +1119,9 @@ export class CliVersionConstraint {
11141119
async supportsDatabaseRegistration() {
11151120
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DB_REGISTRATION);
11161121
}
1122+
1123+
async supportsDatabaseUnbundle() {
1124+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE);
1125+
}
1126+
11171127
}

extensions/ql-vscode/src/databaseFetcher.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import fetch, { Response } from 'node-fetch';
22
import { zip } from 'zip-a-folder';
3+
import * as unzipper from 'unzipper';
34
import {
45
Uri,
56
CancellationToken,
67
commands,
78
window,
89
} from 'vscode';
9-
import {CodeQLCliServer} from './cli';
10+
import { CodeQLCliServer } from './cli';
1011
import * as fs from 'fs-extra';
1112
import * as path from 'path';
1213

@@ -267,10 +268,16 @@ async function readAndUnzip(
267268
step: 9,
268269
message: `Unzipping into ${path.basename(unzipPath)}`
269270
});
270-
// Must get the zip central directory since streaming the
271-
// zip contents may not have correct local file headers.
272-
// Instead, we can only rely on the central directory.
273-
await cli.databaseUnbundle(zipFile, unzipPath);
271+
if(cli.cliConstraints.supportsDatabaseUnbundle()) {
272+
// Use the `database unbundle` command if the installed cli version supports it
273+
await cli.databaseUnbundle(zipFile, unzipPath);
274+
} else {
275+
// Must get the zip central directory since streaming the
276+
// zip contents may not have correct local file headers.
277+
// Instead, we can only rely on the central directory.
278+
const directory = await unzipper.Open.file(zipFile);
279+
await directory.extract({ path: unzipPath });
280+
}
274281
}
275282

276283
async function fetchAndUnzip(

0 commit comments

Comments
 (0)