Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/k8s/src/k8s/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,5 @@ export async function sleep(ms: number): Promise<void> {
}

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' -- {} +`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why + is better than | xargs in this case? Argument splitting?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeahp, basically avoid argument splitting, one less process, so no xargs middleman and better/cleaner exit status propagation

}
29 changes: 29 additions & 0 deletions packages/k8s/tests/k8s-utils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
mergePodSpecWithOptions,
mergeContainerWithOptions,
readExtensionFromFile,
listDirAllCommand,
ENV_HOOK_TEMPLATE_PATH
} from '../src/k8s/utils'
import * as k8s from '@kubernetes/client-node'
Expand Down Expand Up @@ -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')
})
})
})