@@ -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.
@@ -169,14 +194,12 @@ export async function uploadOverlayBaseDatabaseToCache(
169194 return false ;
170195 }
171196
172- // An overlay-base database should contain the base database OIDs file.
173- // Verifying that the file exists serves as a sanity check.
174- const baseDatabaseOidsFilePath = getBaseDatabaseOidsFilePath ( config ) ;
175- if ( ! fs . existsSync ( baseDatabaseOidsFilePath ) ) {
176- logger . warning (
177- "Cannot upload overlay-base database to cache: " +
178- `${ baseDatabaseOidsFilePath } does not exist` ,
179- ) ;
197+ const databaseIsValid = checkOverlayBaseDatabase (
198+ config ,
199+ logger ,
200+ "Abort uploading overlay-base database to cache" ,
201+ ) ;
202+ if ( ! databaseIsValid ) {
180203 return false ;
181204 }
182205
0 commit comments