Skip to content

Commit cdb655d

Browse files
committed
Add random suffix when writing diagnostics to avoid filename collisions
1 parent 19b3a84 commit cdb655d

7 files changed

Lines changed: 19 additions & 7 deletions

File tree

lib/analyze-action.js

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

lib/init-action-post.js

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

lib/init-action.js

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

lib/setup-codeql-action.js

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

lib/upload-lib.js

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

lib/upload-sarif-action.js

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

src/diagnostics.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,16 @@ function writeDiagnostic(
167167
// Create the directory if it doesn't exist yet.
168168
mkdirSync(diagnosticsPath, { recursive: true });
169169

170+
// Include a random suffix to avoid filename collisions between diagnostics
171+
// produced within the same millisecond. This doesn't need to be
172+
// cryptographically secure, so `Math.random` is fine.
173+
const uniqueSuffix = Math.floor(Math.random() * 0x100000000)
174+
.toString(16)
175+
.padStart(8, "0");
170176
const jsonPath = path.resolve(
171177
diagnosticsPath,
172178
// Remove colons from the timestamp as these are not allowed in Windows filenames.
173-
`codeql-action-${diagnostic.timestamp.replaceAll(":", "")}.json`,
179+
`codeql-action-${diagnostic.timestamp.replaceAll(":", "")}-${uniqueSuffix}.json`,
174180
);
175181

176182
writeFileSync(jsonPath, JSON.stringify(diagnostic));

0 commit comments

Comments
 (0)