@@ -8,7 +8,7 @@ import { type CodeQL } from "./codeql";
8
8
import { type Config } from "./config-utils" ;
9
9
import { getCommitOid , getFileOidsUnderPath } from "./git-utils" ;
10
10
import { Logger } from "./logging" ;
11
- import { isInTestMode , withTimeout } from "./util" ;
11
+ import { isInTestMode , tryGetFolderBytes , withTimeout } from "./util" ;
12
12
13
13
export enum OverlayDatabaseMode {
14
14
Overlay = "overlay" ,
@@ -235,41 +235,47 @@ export async function uploadOverlayBaseDatabaseToCache(
235
235
return true ;
236
236
}
237
237
238
+ export interface OverlayBaseDatabaseDownloadStats {
239
+ databaseSizeBytes : number ;
240
+ databaseDownloadDurationMs : number ;
241
+ }
242
+
238
243
/**
239
244
* Downloads the overlay-base database from the GitHub Actions cache. If conditions
240
245
* for downloading are not met, the function does nothing and returns false.
241
246
*
242
247
* @param codeql The CodeQL instance
243
248
* @param config The configuration object
244
249
* @param logger The logger instance
245
- * @returns A promise that resolves to true if the download was performed and
246
- * successfully completed, or false otherwise
250
+ * @returns A promise that resolves to download statistics if an overlay-base
251
+ * database was successfully downloaded, or undefined if the download was
252
+ * either not performed or failed.
247
253
*/
248
254
export async function downloadOverlayBaseDatabaseFromCache (
249
255
codeql : CodeQL ,
250
256
config : Config ,
251
257
logger : Logger ,
252
- ) : Promise < boolean > {
258
+ ) : Promise < OverlayBaseDatabaseDownloadStats | undefined > {
253
259
const overlayDatabaseMode = config . augmentationProperties . overlayDatabaseMode ;
254
260
if ( overlayDatabaseMode !== OverlayDatabaseMode . Overlay ) {
255
261
logger . debug (
256
262
`Overlay database mode is ${ overlayDatabaseMode } . ` +
257
263
"Skip downloading overlay-base database from cache." ,
258
264
) ;
259
- return false ;
265
+ return undefined ;
260
266
}
261
267
if ( ! config . augmentationProperties . useOverlayDatabaseCaching ) {
262
268
logger . debug (
263
269
"Overlay database caching is disabled. " +
264
270
"Skip downloading overlay-base database from cache." ,
265
271
) ;
266
- return false ;
272
+ return undefined ;
267
273
}
268
274
if ( isInTestMode ( ) ) {
269
275
logger . debug (
270
276
"In test mode. Skip downloading overlay-base database from cache." ,
271
277
) ;
272
- return false ;
278
+ return undefined ;
273
279
}
274
280
275
281
const dbLocation = config . dbLocation ;
@@ -280,18 +286,23 @@ export async function downloadOverlayBaseDatabaseFromCache(
280
286
`Looking in Actions cache for overlay-base database with restore key ${ restoreKey } ` ,
281
287
) ;
282
288
289
+ let databaseDownloadDurationMs = 0 ;
283
290
try {
291
+ const databaseDownloadStart = performance . now ( ) ;
284
292
const foundKey = await withTimeout (
285
293
MAX_CACHE_OPERATION_MS ,
286
294
actionsCache . restoreCache ( [ dbLocation ] , restoreKey ) ,
287
295
( ) => {
288
296
logger . info ( "Timed out downloading overlay-base database from cache" ) ;
289
297
} ,
290
298
) ;
299
+ databaseDownloadDurationMs = Math . round (
300
+ performance . now ( ) - databaseDownloadStart ,
301
+ ) ;
291
302
292
303
if ( foundKey === undefined ) {
293
304
logger . info ( "No overlay-base database found in Actions cache" ) ;
294
- return false ;
305
+ return undefined ;
295
306
}
296
307
297
308
logger . info (
@@ -302,7 +313,7 @@ export async function downloadOverlayBaseDatabaseFromCache(
302
313
"Failed to download overlay-base database from cache: " +
303
314
`${ error instanceof Error ? error . message : String ( error ) } ` ,
304
315
) ;
305
- return false ;
316
+ return undefined ;
306
317
}
307
318
308
319
const databaseIsValid = checkOverlayBaseDatabase (
@@ -312,11 +323,26 @@ export async function downloadOverlayBaseDatabaseFromCache(
312
323
) ;
313
324
if ( ! databaseIsValid ) {
314
325
logger . warning ( "Downloaded overlay-base database failed validation" ) ;
315
- return false ;
326
+ return undefined ;
327
+ }
328
+
329
+ const databaseSizeBytes = await tryGetFolderBytes ( dbLocation , logger ) ;
330
+ if ( databaseSizeBytes === undefined ) {
331
+ logger . info (
332
+ "Filesystem error while accessing downloaded overlay-base database" ,
333
+ ) ;
334
+ // The problem that warrants reporting download failure is not that we are
335
+ // unable to determine the size of the database. Rather, it is that we
336
+ // encountered a filesystem error while accessing the database, which
337
+ // indicates that an overlay analysis will likely fail.
338
+ return undefined ;
316
339
}
317
340
318
341
logger . info ( `Successfully downloaded overlay-base database to ${ dbLocation } ` ) ;
319
- return true ;
342
+ return {
343
+ databaseSizeBytes : Math . round ( databaseSizeBytes ) ,
344
+ databaseDownloadDurationMs,
345
+ } ;
320
346
}
321
347
322
348
async function generateCacheKey (
0 commit comments