Skip to content

Commit 245f682

Browse files
committed
Use a counter instead of Math.random for diagnostic filename suffix
1 parent c109008 commit 245f682

7 files changed

Lines changed: 22 additions & 12 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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ let unwrittenDiagnostics: UnwrittenDiagnostic[] = [];
7272
*/
7373
let unwrittenDefaultLanguageDiagnostics: DiagnosticMessage[] = [];
7474

75+
/**
76+
* Counter used to generate a unique suffix for each diagnostic filename, so that
77+
* two diagnostics produced within the same millisecond do not overwrite each
78+
* other on disk.
79+
*/
80+
let diagnosticCounter = 0;
81+
7582
/**
7683
* Constructs a new diagnostic message with the specified id and name, as well as optional additional data.
7784
*
@@ -167,12 +174,9 @@ function writeDiagnostic(
167174
// Create the directory if it doesn't exist yet.
168175
mkdirSync(diagnosticsPath, { recursive: true });
169176

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");
177+
// Include a monotonically increasing suffix to avoid filename collisions
178+
// between diagnostics produced within the same millisecond.
179+
const uniqueSuffix = (diagnosticCounter++).toString();
176180
// We should only need to remove colons, but to be defensive, only allow a restricted set of
177181
// characters.
178182
const sanitizedTimestamp = diagnostic.timestamp.replace(

0 commit comments

Comments
 (0)