Skip to content

Commit c82e09a

Browse files
Delete bundled db before recreating
1 parent 460d053 commit c82e09a

6 files changed

Lines changed: 28 additions & 10 deletions

File tree

lib/database-upload.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/database-upload.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/database-upload.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export async function uploadDatabases(
5757

5858
const codeql = await getCodeQL(config.codeQLCmd);
5959
for (const language of config.languages) {
60-
// Upload the database bundle
60+
// Upload the database bundle.
61+
// Although we are uploading arbitrary file contents to the API, it's worth
62+
// noting that it's the API's job to validate that the contents is acceptable.
63+
// This API method is available to anyone with write access to the repo.
6164
const payload = fs.readFileSync(await bundleDb(config, language, codeql));
6265
try {
6366
if (useUploadDomain) {

src/util.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,15 @@ export async function bundleDb(
559559
config.dbLocation,
560560
`${databasePath}.zip`
561561
);
562-
if (!fs.existsSync(databaseBundlePath)) {
563-
await codeql.databaseBundle(databasePath, databaseBundlePath);
564-
}
562+
// For a tiny bit of added safety, delete the file if it exists.
563+
// The file is probably from an earlier call to this function, either
564+
// as part of this action step or a previous one, but it could also be
565+
// from somewhere else or someone trying to make the action upload a
566+
// non-database file.
567+
if (fs.existsSync(databaseBundlePath)) {
568+
fs.rmSync(databaseBundlePath, { recursive: true });
569+
}
570+
await codeql.databaseBundle(databasePath, databaseBundlePath);
565571
return databaseBundlePath;
566572
}
567573

0 commit comments

Comments
 (0)