@@ -235,25 +235,24 @@ function validatePatchPaths(patch: string, changed: RunnerWorkspaceChangedFile[]
235235
236236async function snapshotWorkspace ( root : string ) : Promise < RunnerWorkspacePublicationFile [ ] > {
237237 const output : RunnerWorkspacePublicationFile [ ] = [ ]
238- async function visit ( directory : string ) : Promise < void > {
239- for ( const entry of await readdir ( directory , { withFileTypes : true } ) ) {
240- if ( entry . name === ".git" || entry . name === ".codebox" ) continue
241- const absolute = resolve ( directory , entry . name )
242- const path = relative ( root , absolute ) . replaceAll ( "\\" , "/" )
243- const stat = await lstat ( absolute )
244- if ( stat . isSymbolicLink ( ) ) throw new Error ( `Runner workspace contains an unsupported path type: ${ path } ` )
245- if ( stat . isDirectory ( ) ) {
246- await visit ( absolute )
247- continue
248- }
249- if ( ! stat . isFile ( ) ) throw new Error ( `Runner workspace contains an unsupported path type: ${ path } ` )
250- const mode = ( stat . mode & 0o111 ) ? "100755" : "100644"
251- const bytes = await readFile ( absolute )
252- output . push ( { path, mode, content : bytes . toString ( "base64" ) , sha256 : createHash ( "sha256" ) . update ( bytes ) . digest ( "hex" ) , deleted : false } )
238+ const { stdout } = await execFileAsync ( "git" , [ "ls-files" , "--cached" , "--others" , "--exclude-standard" , "-z" ] , { cwd : root , maxBuffer : MAX_PATCH_BYTES } )
239+ const paths = stdout . split ( "\0" ) . filter ( Boolean ) . sort ( ( left , right ) => left . localeCompare ( right ) )
240+ for ( const path of paths ) {
241+ const absolute = resolve ( root , path )
242+ if ( ! pathIsWithinRoot ( absolute , root ) ) throw new Error ( `Runner workspace contains a denied path: ${ path } ` )
243+ let stat
244+ try {
245+ stat = await lstat ( absolute )
246+ } catch ( error ) {
247+ if ( ( error as NodeJS . ErrnoException ) . code === "ENOENT" ) continue
248+ throw error
253249 }
250+ if ( stat . isSymbolicLink ( ) || ! stat . isFile ( ) ) throw new Error ( `Runner workspace contains an unsupported path type: ${ path } ` )
251+ const mode = ( stat . mode & 0o111 ) ? "100755" : "100644"
252+ const bytes = await readFile ( absolute )
253+ output . push ( { path, mode, content : bytes . toString ( "base64" ) , sha256 : createHash ( "sha256" ) . update ( bytes ) . digest ( "hex" ) , deleted : false } )
254254 }
255- await visit ( root )
256- return output . sort ( ( a , b ) => a . path . localeCompare ( b . path ) )
255+ return output
257256}
258257
259258function validateAppliedWorkspace ( baseline : RunnerWorkspacePublicationFile [ ] , current : RunnerWorkspacePublicationFile [ ] , changed : RunnerWorkspaceChangedFile [ ] ) : void {
0 commit comments