11import fetch , { Response } from "node-fetch" ;
22import { zip } from "zip-a-folder" ;
3- import { Open } from "unzipper" ;
43import { Uri , window , InputBoxOptions } from "vscode" ;
54import { CodeQLCliServer } from "../codeql-cli/cli" ;
65import {
@@ -46,7 +45,7 @@ export async function promptImportInternetDatabase(
4645 databaseManager : DatabaseManager ,
4746 storagePath : string ,
4847 progress : ProgressCallback ,
49- cli ? : CodeQLCliServer ,
48+ cli : CodeQLCliServer ,
5049) : Promise < DatabaseItem | undefined > {
5150 const databaseUrl = await window . showInputBox ( {
5251 prompt : "Enter URL of zipfile of database to download" ,
@@ -101,7 +100,7 @@ export async function promptImportGithubDatabase(
101100 storagePath : string ,
102101 credentials : Credentials | undefined ,
103102 progress : ProgressCallback ,
104- cli ? : CodeQLCliServer ,
103+ cli : CodeQLCliServer ,
105104 language ?: string ,
106105 makeSelected = true ,
107106 addSourceArchiveFolder = addDatabaseSourceToWorkspace ( ) ,
@@ -180,7 +179,7 @@ export async function downloadGitHubDatabase(
180179 storagePath : string ,
181180 credentials : Credentials | undefined ,
182181 progress : ProgressCallback ,
183- cli ? : CodeQLCliServer ,
182+ cli : CodeQLCliServer ,
184183 language ?: string ,
185184 makeSelected = true ,
186185 addSourceArchiveFolder = addDatabaseSourceToWorkspace ( ) ,
@@ -235,7 +234,7 @@ export async function downloadGitHubDatabaseFromUrl(
235234 progress : ProgressCallback ,
236235 databaseManager : DatabaseManager ,
237236 storagePath : string ,
238- cli ? : CodeQLCliServer ,
237+ cli : CodeQLCliServer ,
239238 makeSelected = true ,
240239 addSourceArchiveFolder = true ,
241240) : Promise < DatabaseItem | undefined > {
@@ -279,14 +278,15 @@ export async function downloadGitHubDatabaseFromUrl(
279278 * @param databaseUrl the file url of the archive to import
280279 * @param databaseManager the DatabaseManager
281280 * @param storagePath where to store the unzipped database.
281+ * @param cli the CodeQL CLI server
282282 */
283283export async function importArchiveDatabase (
284284 commandManager : AppCommandManager ,
285285 databaseUrl : string ,
286286 databaseManager : DatabaseManager ,
287287 storagePath : string ,
288288 progress : ProgressCallback ,
289- cli ? : CodeQLCliServer ,
289+ cli : CodeQLCliServer ,
290290) : Promise < DatabaseItem | undefined > {
291291 try {
292292 const item = await databaseArchiveFetcher (
@@ -333,6 +333,7 @@ export async function importArchiveDatabase(
333333 * @param nameOverride a name for the database that overrides the default
334334 * @param origin the origin of the database
335335 * @param progress callback to send progress messages to
336+ * @param cli the CodeQL CLI server
336337 * @param makeSelected make the new database selected in the databases panel (default: true)
337338 * @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
338339 */
@@ -344,7 +345,7 @@ async function databaseArchiveFetcher(
344345 nameOverride : string | undefined ,
345346 origin : DatabaseOrigin ,
346347 progress : ProgressCallback ,
347- cli ? : CodeQLCliServer ,
348+ cli : CodeQLCliServer ,
348349 makeSelected = true ,
349350 addSourceArchiveFolder = addDatabaseSourceToWorkspace ( ) ,
350351) : Promise < DatabaseItem > {
@@ -443,34 +444,24 @@ function validateUrl(databaseUrl: string) {
443444async function readAndUnzip (
444445 zipUrl : string ,
445446 unzipPath : string ,
446- cli ? : CodeQLCliServer ,
447+ cli : CodeQLCliServer ,
447448 progress ?: ProgressCallback ,
448449) {
449- // TODO: Providing progress as the file is unzipped is currently blocked
450- // on https://github.com/ZJONSSON/node-unzipper/issues/222
451450 const zipFile = Uri . parse ( zipUrl ) . fsPath ;
452451 progress ?.( {
453452 maxStep : 10 ,
454453 step : 9 ,
455454 message : `Unzipping into ${ basename ( unzipPath ) } ` ,
456455 } ) ;
457- if ( cli ) {
458- // Use the `database unbundle` command if the installed cli version supports it
459- await cli . databaseUnbundle ( zipFile , unzipPath ) ;
460- } else {
461- // Must get the zip central directory since streaming the
462- // zip contents may not have correct local file headers.
463- // Instead, we can only rely on the central directory.
464- const directory = await Open . file ( zipFile ) ;
465- await directory . extract ( { path : unzipPath } ) ;
466- }
456+
457+ await cli . databaseUnbundle ( zipFile , unzipPath ) ;
467458}
468459
469460async function fetchAndUnzip (
470461 databaseUrl : string ,
471462 requestHeaders : { [ key : string ] : string } ,
472463 unzipPath : string ,
473- cli ? : CodeQLCliServer ,
464+ cli : CodeQLCliServer ,
474465 progress ?: ProgressCallback ,
475466) {
476467 // Although it is possible to download and stream directly to an unzipped directory,
0 commit comments