@@ -602,39 +602,38 @@ export function createNodeWorkspaceTransferService(options: {
602602 params . signal . throwIfAborted ( ) ;
603603 assertAuthorizationCurrent ( authorization ) ;
604604 } ;
605- assertCurrent ( ) ;
606- const contentLength = Number ( params . request . headers [ "content-length" ] ) ;
607- if (
608- ! Number . isSafeInteger ( contentLength ) ||
609- contentLength < 8 ||
610- contentLength > MAX_UPLOAD_BYTES
611- ) {
612- throw new NodeWorkspaceTransferLimitError (
613- "Workspace transfer upload exceeds its byte limit" ,
614- ) ;
615- }
616- const reader = new RequestByteReader ( params . request , params . signal , assertCurrent ) ;
617- const readManifest = async ( expectedRef ?: string ) => {
618- const bytes = ( await reader . readExactly ( 4 ) ) . readUInt32BE ( ) ;
619- if ( bytes < 2 || bytes > MAX_WORKSPACE_MANIFEST_BYTES ) {
605+ let stagingRoot : string | undefined ;
606+ try {
607+ assertCurrent ( ) ;
608+ const contentLength = Number ( params . request . headers [ "content-length" ] ) ;
609+ if (
610+ ! Number . isSafeInteger ( contentLength ) ||
611+ contentLength < 8 ||
612+ contentLength > MAX_UPLOAD_BYTES
613+ ) {
620614 throw new NodeWorkspaceTransferLimitError (
621- "Workspace transfer manifest exceeds its byte limit" ,
615+ "Workspace transfer upload exceeds its byte limit" ,
622616 ) ;
623617 }
624- const raw = ( await reader . readExactly ( bytes ) ) . toString ( "utf8" ) ;
625- const ref = expectedRef ?? `sha256:${ createHash ( "sha256" ) . update ( raw ) . digest ( "hex" ) } ` ;
626- return { raw, ref, manifest : parseWorkerWorkspaceManifest ( raw , ref ) } ;
627- } ;
628- const base = await readManifest ( operation . baseManifestRef ) ;
629- assertCurrent ( ) ;
630- const current = await readManifest ( ) ;
631- assertCurrent ( ) ;
632- const transferPaths = workerWorkspaceTransferPaths ( current . manifest , base . manifest ) ;
633- const transferPathSet = new Set ( transferPaths ) ;
634- const stagingRoot = await fsp . mkdtemp (
635- path . join ( authorization . context . temporaryRoot , "upload-" ) ,
636- ) ;
637- try {
618+ const reader = new RequestByteReader ( params . request , params . signal , assertCurrent ) ;
619+ const readManifest = async ( expectedRef ?: string ) => {
620+ const bytes = ( await reader . readExactly ( 4 ) ) . readUInt32BE ( ) ;
621+ if ( bytes < 2 || bytes > MAX_WORKSPACE_MANIFEST_BYTES ) {
622+ throw new NodeWorkspaceTransferLimitError (
623+ "Workspace transfer manifest exceeds its byte limit" ,
624+ ) ;
625+ }
626+ const raw = ( await reader . readExactly ( bytes ) ) . toString ( "utf8" ) ;
627+ const ref = expectedRef ?? `sha256:${ createHash ( "sha256" ) . update ( raw ) . digest ( "hex" ) } ` ;
628+ return { raw, ref, manifest : parseWorkerWorkspaceManifest ( raw , ref ) } ;
629+ } ;
630+ const base = await readManifest ( operation . baseManifestRef ) ;
631+ assertCurrent ( ) ;
632+ const current = await readManifest ( ) ;
633+ assertCurrent ( ) ;
634+ const transferPaths = workerWorkspaceTransferPaths ( current . manifest , base . manifest ) ;
635+ const transferPathSet = new Set ( transferPaths ) ;
636+ stagingRoot = await fsp . mkdtemp ( path . join ( authorization . context . temporaryRoot , "upload-" ) ) ;
638637 const currentByPath = new Map ( current . manifest . entries . map ( ( entry ) => [ entry . path , entry ] ) ) ;
639638 for ( const relative of transferPaths ) {
640639 const entry = currentByPath . get ( relative ) ;
@@ -680,7 +679,9 @@ export function createNodeWorkspaceTransferService(options: {
680679 operation . state = "completed" ;
681680 return { manifestRef : current . ref } ;
682681 } catch ( error ) {
683- await fsp . rm ( stagingRoot , { recursive : true , force : true } ) ;
682+ if ( stagingRoot ) {
683+ await fsp . rm ( stagingRoot , { recursive : true , force : true } ) ;
684+ }
684685 if ( authorization . context . upload === operation ) {
685686 authorization . context . upload = undefined ;
686687 }
0 commit comments