@@ -132,6 +132,31 @@ const CACHE_VERSION = 1;
132132const CACHE_PREFIX = "codeql-overlay-base-database" ;
133133const MAX_CACHE_OPERATION_MS = 120_000 ; // Two minutes
134134
135+ /**
136+ * Checks that the overlay-base database is valid by checking for the
137+ * existence of the base database OIDs file.
138+ *
139+ * @param config The configuration object
140+ * @param logger The logger instance
141+ * @param warningPrefix Prefix for the check failure warning message
142+ * @returns True if the verification succeeded, false otherwise
143+ */
144+ export function checkOverlayBaseDatabase (
145+ config : Config ,
146+ logger : Logger ,
147+ warningPrefix : string ,
148+ ) : boolean {
149+ // An overlay-base database should contain the base database OIDs file.
150+ const baseDatabaseOidsFilePath = getBaseDatabaseOidsFilePath ( config ) ;
151+ if ( ! fs . existsSync ( baseDatabaseOidsFilePath ) ) {
152+ logger . warning (
153+ `${ warningPrefix } : ${ baseDatabaseOidsFilePath } does not exist` ,
154+ ) ;
155+ return false ;
156+ }
157+ return true ;
158+ }
159+
135160/**
136161 * Uploads the overlay-base database to the GitHub Actions cache. If conditions
137162 * for uploading are not met, the function does nothing and returns false.
@@ -172,14 +197,12 @@ export async function uploadOverlayBaseDatabaseToCache(
172197 return false ;
173198 }
174199
175- // An overlay-base database should contain the base database OIDs file.
176- // Verifying that the file exists serves as a sanity check.
177- const baseDatabaseOidsFilePath = getBaseDatabaseOidsFilePath ( config ) ;
178- if ( ! fs . existsSync ( baseDatabaseOidsFilePath ) ) {
179- logger . warning (
180- "Cannot upload overlay-base database to cache: " +
181- `${ baseDatabaseOidsFilePath } does not exist` ,
182- ) ;
200+ const databaseIsValid = checkOverlayBaseDatabase (
201+ config ,
202+ logger ,
203+ "Abort uploading overlay-base database to cache" ,
204+ ) ;
205+ if ( ! databaseIsValid ) {
183206 return false ;
184207 }
185208
0 commit comments