Skip to content

Commit e787bc7

Browse files
committed
Extract checkOverlayBaseDatabase()
1 parent 89f5989 commit e787bc7

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

src/overlay-database-utils.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,31 @@ const CACHE_VERSION = 1;
132132
const CACHE_PREFIX = "codeql-overlay-base-database";
133133
const 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

Comments
 (0)