| 509 | } |
| 510 | |
| 511 | function directorySizeBytes(dir: string): number { |
| 512 | // Use spawnSync (no shell) instead of execSync so `dir` is passed as |
| 513 | // an argv element rather than interpolated into a shell command — |
| 514 | // CodeQL's `js/shell-command-injected-from-environment` rule fires |
| 515 | // on the latter even with JSON-quoting. `du -sb` is Linux-only; |
| 516 | // build-zip is CI-side where Linux coreutils is present. |
| 517 | const result = spawnSync("du", ["-sb", dir], { encoding: "utf-8" }); |
| 518 | if (result.status === 0 && result.stdout) { |
| 519 | const bytes = Number.parseInt(result.stdout.split(/\s+/)[0] ?? "0", 10); |
| 520 | if (!Number.isNaN(bytes)) return bytes; |
| 521 | } |
| 522 | return walkSize(dir); |
| 523 | } |
| 524 | |
| 525 | function walkSize(dir: string): number { |
| 526 | let total = 0; |