Skip to content

Commit

Permalink
Delete bundled db before recreating
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed Dec 1, 2021
1 parent 460d053 commit c82e09a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lib/database-upload.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/database-upload.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/database-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export async function uploadDatabases(

const codeql = await getCodeQL(config.codeQLCmd);
for (const language of config.languages) {
// Upload the database bundle
// Upload the database bundle.
// Although we are uploading arbitrary file contents to the API, it's worth
// noting that it's the API's job to validate that the contents is acceptable.
// This API method is available to anyone with write access to the repo.
const payload = fs.readFileSync(await bundleDb(config, language, codeql));
try {
if (useUploadDomain) {
Expand Down
12 changes: 9 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,15 @@ export async function bundleDb(
config.dbLocation,
`${databasePath}.zip`
);
if (!fs.existsSync(databaseBundlePath)) {
await codeql.databaseBundle(databasePath, databaseBundlePath);
}
// For a tiny bit of added safety, delete the file if it exists.
// The file is probably from an earlier call to this function, either
// as part of this action step or a previous one, but it could also be
// from somewhere else or someone trying to make the action upload a
// non-database file.
if (fs.existsSync(databaseBundlePath)) {
fs.rmSync(databaseBundlePath, { recursive: true });
}
await codeql.databaseBundle(databasePath, databaseBundlePath);
return databaseBundlePath;
}

Expand Down

0 comments on commit c82e09a

Please sign in to comment.