Account for existing but empty cpus file

If a CPU file exists but is empty, previously we reported this file with a CPU count of 1, which resulted in a single-threaded run.
This commit is contained in:
Angela P Wen 2024-02-15 14:31:37 +00:00
parent 65b0987dbe
commit ef0a773901
4 changed files with 10 additions and 4 deletions

View file

@ -6,7 +6,7 @@ Note that the only difference between `v2` and `v3` of the CodeQL Action is the
## [UNRELEASED]
No user facing changes.
- Fix an issue where an existing, but empty, `/sys/fs/cgroup/cpuset.cpus` file always resulted in a single-threaded run. [#2151](https://github.com/github/codeql-action/pull/2151)
## 3.24.3 - 15 Feb 2024

5
lib/util.js generated
View file

@ -316,7 +316,10 @@ function getCgroupCpuCountFromCpus(cpusFile, logger) {
}
let cpuCount = 0;
// Comma-separated numbers and ranges, for eg. 0-1,3
const cpusString = fs.readFileSync(cpusFile, "utf-8");
const cpusString = fs.readFileSync(cpusFile, "utf-8").trim();
if (cpusString.length === 0) {
return undefined;
}
for (const token of cpusString.split(",")) {
if (!token.includes("-")) {
// Not a range

File diff suppressed because one or more lines are too long

View file

@ -453,7 +453,10 @@ function getCgroupCpuCountFromCpus(
let cpuCount = 0;
// Comma-separated numbers and ranges, for eg. 0-1,3
const cpusString = fs.readFileSync(cpusFile, "utf-8");
const cpusString = fs.readFileSync(cpusFile, "utf-8").trim();
if (cpusString.length === 0) {
return undefined;
}
for (const token of cpusString.split(",")) {
if (!token.includes("-")) {
// Not a range