Skip to content

Commit d307e59

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

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
@@ -785,7 +785,9 @@ async function run() {
785785
);
786786
config.augmentationProperties.overlayDatabaseMode =
787787
OverlayDatabaseMode.None;
788-
cleanupDatabaseClusterDirectory(config, logger);
788+
cleanupDatabaseClusterDirectory(config, logger, {
789+
disableExistingDirectoryWarning: true,
790+
});
789791
await runDatabaseInitCluster(
790792
databaseInitEnvironment,
791793
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: KnownLanguage;
117145
packinfoContents: string | undefined;

src/init.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export async function checkInstallPython311(
236236
export function cleanupDatabaseClusterDirectory(
237237
config: configUtils.Config,
238238
logger: Logger,
239+
options: { disableExistingDirectoryWarning?: boolean } = {},
239240
// We can't stub the fs module in tests, so we allow the caller to override the rmSync function
240241
// for testing.
241242
rmSync = fs.rmSync,
@@ -245,9 +246,11 @@ export function cleanupDatabaseClusterDirectory(
245246
(fs.statSync(config.dbLocation).isFile() ||
246247
fs.readdirSync(config.dbLocation).length > 0)
247248
) {
248-
logger.warning(
249-
`The database cluster directory ${config.dbLocation} must be empty. Attempting to clean it up.`,
250-
);
249+
if (!options.disableExistingDirectoryWarning) {
250+
logger.warning(
251+
`The database cluster directory ${config.dbLocation} must be empty. Attempting to clean it up.`,
252+
);
253+
}
251254
try {
252255
rmSync(config.dbLocation, {
253256
force: true,

0 commit comments

Comments
 (0)