From 8beca909f3512fd63ebc50a7e9fae7bfe320c7e9 Mon Sep 17 00:00:00 2001 From: Jean Schmidt Date: Wed, 22 Apr 2026 13:57:59 -0700 Subject: [PATCH 1/2] perf: batch find -exec calls with {} + - Replace `\;` with `+` in find -exec for stat Using `{} +` batches filenames into fewer stat invocations instead of spawning one process per file, reducing fork/exec overhead in large dirs. Signed-off-by: Jean Schmidt --- packages/k8s/src/k8s/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/k8s/src/k8s/utils.ts b/packages/k8s/src/k8s/utils.ts index 9e744004..254209a4 100644 --- a/packages/k8s/src/k8s/utils.ts +++ b/packages/k8s/src/k8s/utils.ts @@ -301,5 +301,5 @@ export async function sleep(ms: number): Promise { } export function listDirAllCommand(dir: string): string { - return `cd ${shlex.quote(dir)} && find . -type f -not -path '*/_runner_hook_responses*' -exec stat -c '%s %n' {} \\;` + return `cd ${shlex.quote(dir)} && find . -type f -not -path '*/_runner_hook_responses*' -exec stat -c '%s %n' {} +` } From 8e9457620f44e0cfc0aa4bb87fc7341f7758118f Mon Sep 17 00:00:00 2001 From: Jean Schmidt Date: Wed, 22 Apr 2026 14:39:41 -0700 Subject: [PATCH 2/2] fix: add end-of-options marker to stat call - Add `--` before `{}` in stat command to prevent filenames starting with `-` from being interpreted as options - Add tests for listDirAllCommand covering batched exec, end-of-options marker, directory quoting, path exclusion, and file type filtering Notes: Without the `--` end-of-options marker, files whose names begin with a dash (e.g. `-rf`) could be misinterpreted as flags by `stat`, causing silent failures or incorrect output during workspace file listing. Signed-off-by: Jean Schmidt --- packages/k8s/src/k8s/utils.ts | 2 +- packages/k8s/tests/k8s-utils-test.ts | 29 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/k8s/src/k8s/utils.ts b/packages/k8s/src/k8s/utils.ts index 254209a4..7d1f6bac 100644 --- a/packages/k8s/src/k8s/utils.ts +++ b/packages/k8s/src/k8s/utils.ts @@ -301,5 +301,5 @@ export async function sleep(ms: number): Promise { } export function listDirAllCommand(dir: string): string { - return `cd ${shlex.quote(dir)} && find . -type f -not -path '*/_runner_hook_responses*' -exec stat -c '%s %n' {} +` + return `cd ${shlex.quote(dir)} && find . -type f -not -path '*/_runner_hook_responses*' -exec stat -c '%s %n' -- {} +` } diff --git a/packages/k8s/tests/k8s-utils-test.ts b/packages/k8s/tests/k8s-utils-test.ts index bfb6c453..87a01809 100644 --- a/packages/k8s/tests/k8s-utils-test.ts +++ b/packages/k8s/tests/k8s-utils-test.ts @@ -6,6 +6,7 @@ import { mergePodSpecWithOptions, mergeContainerWithOptions, readExtensionFromFile, + listDirAllCommand, ENV_HOOK_TEMPLATE_PATH } from '../src/k8s/utils' import * as k8s from '@kubernetes/client-node' @@ -406,4 +407,32 @@ spec: expect(base).toStrictEqual(expected) }) + + describe('listDirAllCommand', () => { + it('should use batched exec (+ not \\;)', () => { + const cmd = listDirAllCommand('/workspace') + expect(cmd).toContain('{} +') + expect(cmd).not.toContain('\\;') + }) + + it('should include end-of-options marker before filenames', () => { + const cmd = listDirAllCommand('/workspace') + expect(cmd).toMatch(/stat -c '%s %n' -- \{\} \+/) + }) + + it('should quote the directory path', () => { + const cmd = listDirAllCommand('/path with spaces') + expect(cmd).toContain("'/path with spaces'") + }) + + it('should exclude _runner_hook_responses', () => { + const cmd = listDirAllCommand('/workspace') + expect(cmd).toContain("-not -path '*/_runner_hook_responses*'") + }) + + it('should only find regular files', () => { + const cmd = listDirAllCommand('/workspace') + expect(cmd).toContain('-type f') + }) + }) })