@@ -29,11 +29,11 @@ import { tmpDir } from './run-queries';
2929 * @param storagePath where to store the unzipped database.
3030 */
3131export async function promptImportInternetDatabase (
32- cli : CodeQLCliServer ,
3332 databaseManager : DatabaseManager ,
3433 storagePath : string ,
3534 progress : ProgressCallback ,
3635 token : CancellationToken ,
36+ cli ?: CodeQLCliServer
3737) : Promise < DatabaseItem | undefined > {
3838 const databaseUrl = await window . showInputBox ( {
3939 prompt : 'Enter URL of zipfile of database to download' ,
@@ -45,12 +45,12 @@ export async function promptImportInternetDatabase(
4545 validateHttpsUrl ( databaseUrl ) ;
4646
4747 const item = await databaseArchiveFetcher (
48- cli ,
4948 databaseUrl ,
5049 databaseManager ,
5150 storagePath ,
5251 progress ,
53- token
52+ token ,
53+ cli
5454 ) ;
5555
5656 if ( item ) {
@@ -70,11 +70,11 @@ export async function promptImportInternetDatabase(
7070 * @param storagePath where to store the unzipped database.
7171 */
7272export async function promptImportLgtmDatabase (
73- cli : CodeQLCliServer ,
7473 databaseManager : DatabaseManager ,
7574 storagePath : string ,
7675 progress : ProgressCallback ,
77- token : CancellationToken
76+ token : CancellationToken ,
77+ cli ?: CodeQLCliServer
7878) : Promise < DatabaseItem | undefined > {
7979 progress ( {
8080 message : 'Choose project' ,
@@ -93,12 +93,12 @@ export async function promptImportLgtmDatabase(
9393 const databaseUrl = await convertToDatabaseUrl ( lgtmUrl , progress ) ;
9494 if ( databaseUrl ) {
9595 const item = await databaseArchiveFetcher (
96- cli ,
9796 databaseUrl ,
9897 databaseManager ,
9998 storagePath ,
10099 progress ,
101- token
100+ token ,
101+ cli
102102 ) ;
103103 if ( item ) {
104104 await commands . executeCommand ( 'codeQLDatabases.focus' ) ;
@@ -120,21 +120,21 @@ export async function promptImportLgtmDatabase(
120120 * @param storagePath where to store the unzipped database.
121121 */
122122export async function importArchiveDatabase (
123- cli : CodeQLCliServer ,
124123 databaseUrl : string ,
125124 databaseManager : DatabaseManager ,
126125 storagePath : string ,
127126 progress : ProgressCallback ,
128127 token : CancellationToken ,
128+ cli ?: CodeQLCliServer ,
129129) : Promise < DatabaseItem | undefined > {
130130 try {
131131 const item = await databaseArchiveFetcher (
132- cli ,
133132 databaseUrl ,
134133 databaseManager ,
135134 storagePath ,
136135 progress ,
137- token
136+ token ,
137+ cli
138138 ) ;
139139 if ( item ) {
140140 await commands . executeCommand ( 'codeQLDatabases.focus' ) ;
@@ -162,12 +162,12 @@ export async function importArchiveDatabase(
162162 * @param token cancellation token
163163 */
164164async function databaseArchiveFetcher (
165- cli : CodeQLCliServer ,
166165 databaseUrl : string ,
167166 databaseManager : DatabaseManager ,
168167 storagePath : string ,
169168 progress : ProgressCallback ,
170- token : CancellationToken
169+ token : CancellationToken ,
170+ cli ?: CodeQLCliServer ,
171171) : Promise < DatabaseItem > {
172172 progress ( {
173173 message : 'Getting database' ,
@@ -181,9 +181,9 @@ async function databaseArchiveFetcher(
181181 const unzipPath = await getStorageFolder ( storagePath , databaseUrl ) ;
182182
183183 if ( isFile ( databaseUrl ) ) {
184- await readAndUnzip ( cli , databaseUrl , unzipPath , progress ) ;
184+ await readAndUnzip ( databaseUrl , unzipPath , cli , progress ) ;
185185 } else {
186- await fetchAndUnzip ( cli , databaseUrl , unzipPath , progress ) ;
186+ await fetchAndUnzip ( databaseUrl , unzipPath , cli , progress ) ;
187187 }
188188
189189 progress ( {
@@ -255,9 +255,9 @@ function validateHttpsUrl(databaseUrl: string) {
255255}
256256
257257async function readAndUnzip (
258- cli : CodeQLCliServer ,
259258 zipUrl : string ,
260259 unzipPath : string ,
260+ cli ?: CodeQLCliServer ,
261261 progress ?: ProgressCallback
262262) {
263263 // TODO: Providing progress as the file is unzipped is currently blocked
@@ -268,7 +268,7 @@ async function readAndUnzip(
268268 step : 9 ,
269269 message : `Unzipping into ${ path . basename ( unzipPath ) } `
270270 } ) ;
271- if ( await cli . cliConstraints . supportsDatabaseUnbundle ( ) ) {
271+ if ( cli !== undefined && await cli . cliConstraints . supportsDatabaseUnbundle ( ) ) {
272272 // Use the `database unbundle` command if the installed cli version supports it
273273 await cli . databaseUnbundle ( zipFile , unzipPath ) ;
274274 } else {
@@ -281,9 +281,9 @@ async function readAndUnzip(
281281}
282282
283283async function fetchAndUnzip (
284- cli : CodeQLCliServer ,
285284 databaseUrl : string ,
286285 unzipPath : string ,
286+ cli ?: CodeQLCliServer ,
287287 progress ?: ProgressCallback
288288) {
289289 // Although it is possible to download and stream directly to an unzipped directory,
@@ -312,8 +312,9 @@ async function fetchAndUnzip(
312312 . on ( 'finish' , resolve )
313313 . on ( 'error' , reject )
314314 ) ;
315-
316- await readAndUnzip ( cli , Uri . file ( archivePath ) . toString ( true ) , unzipPath , progress ) ;
315+ if ( cli && await cli . cliConstraints . supportsDatabaseUnbundle ( ) ) {
316+ await readAndUnzip ( Uri . file ( archivePath ) . toString ( true ) , unzipPath , cli , progress ) ;
317+ }
317318
318319 // remove archivePath eagerly since these archives can be large.
319320 await fs . remove ( archivePath ) ;
0 commit comments