Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee698cb

Browse files
committed
init-action: inhibit non-empty dbLocation warning when restarting
1 parent bc9c32e commit ee698cb

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
@@ -238,6 +238,7 @@ export async function checkInstallPython311(
238238
export function cleanupDatabaseClusterDirectory(
239239
config: configUtils.Config,
240240
logger: Logger,
241+
options: { disableExistingDirectoryWarning?: boolean } = {},
241242
// We can't stub the fs module in tests, so we allow the caller to override the rmSync function
242243
// for testing.
243244
rmSync = fs.rmSync,
@@ -247,9 +248,11 @@ export function cleanupDatabaseClusterDirectory(
247248
(fs.statSync(config.dbLocation).isFile() ||
248249
fs.readdirSync(config.dbLocation).length > 0)
249250
) {
250-
logger.warning(
251-
`The database cluster directory ${config.dbLocation} must be empty. Attempting to clean it up.`,
252-
);
251+
if (!options.disableExistingDirectoryWarning) {
252+
logger.warning(
253+
`The database cluster directory ${config.dbLocation} must be empty. Attempting to clean it up.`,
254+
);
255+
}
253256
try {
254257
rmSync(config.dbLocation, {
255258
force: true,

0 commit comments

Comments
 (0)