Skip to content

Commit 7066904

Browse files
committed
init-action: inhibit non-empty dbLocation warning when restarting
1 parent 4e500d9 commit 7066904

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/init-action.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,9 @@ async function run() {
752752
);
753753
config.augmentationProperties.overlayDatabaseMode =
754754
OverlayDatabaseMode.None;
755-
cleanupDatabaseClusterDirectory(config, logger);
755+
cleanupDatabaseClusterDirectory(config, logger, {
756+
disableExistingDirectoryWarning: true,
757+
});
756758
await runDatabaseInitCluster(
757759
databaseInitEnvironment,
758760
codeql,

src/init.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ for (const { runnerEnv, ErrorConstructor, message } of [
9292
cleanupDatabaseClusterDirectory(
9393
createTestConfig({ dbLocation }),
9494
getRecordingLogger(messages),
95+
{},
9596
() => {
9697
throw new Error(rmSyncError);
9798
},
@@ -112,6 +113,33 @@ for (const { runnerEnv, ErrorConstructor, message } of [
112113
});
113114
}
114115

116+
test("cleanupDatabaseClusterDirectory can disable warning with options", async (t) => {
117+
await withTmpDir(async (tmpDir: string) => {
118+
const dbLocation = path.resolve(tmpDir, "dbs");
119+
fs.mkdirSync(dbLocation, { recursive: true });
120+
121+
const fileToCleanUp = path.resolve(dbLocation, "something-to-cleanup.txt");
122+
fs.writeFileSync(fileToCleanUp, "");
123+
124+
const messages: LoggedMessage[] = [];
125+
cleanupDatabaseClusterDirectory(
126+
createTestConfig({ dbLocation }),
127+
getRecordingLogger(messages),
128+
{ disableExistingDirectoryWarning: true },
129+
);
130+
131+
// Should only have the info message, not the warning
132+
t.is(messages.length, 1);
133+
t.is(messages[0].type, "info");
134+
t.is(
135+
messages[0].message,
136+
`Cleaned up database cluster directory ${dbLocation}.`,
137+
);
138+
139+
t.false(fs.existsSync(fileToCleanUp));
140+
});
141+
});
142+
115143
type PackInfo = {
116144
language: Language;
117145
packinfoContents: string | undefined;

src/init.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export async function checkInstallPython311(
226226
export function cleanupDatabaseClusterDirectory(
227227
config: configUtils.Config,
228228
logger: Logger,
229+
options: { disableExistingDirectoryWarning?: boolean } = {},
229230
// We can't stub the fs module in tests, so we allow the caller to override the rmSync function
230231
// for testing.
231232
rmSync = fs.rmSync,
@@ -235,9 +236,11 @@ export function cleanupDatabaseClusterDirectory(
235236
(fs.statSync(config.dbLocation).isFile() ||
236237
fs.readdirSync(config.dbLocation).length)
237238
) {
238-
logger.warning(
239-
`The database cluster directory ${config.dbLocation} must be empty. Attempting to clean it up.`,
240-
);
239+
if (!options.disableExistingDirectoryWarning) {
240+
logger.warning(
241+
`The database cluster directory ${config.dbLocation} must be empty. Attempting to clean it up.`,
242+
);
243+
}
241244
try {
242245
rmSync(config.dbLocation, {
243246
force: true,

0 commit comments

Comments
 (0)