@@ -423,14 +423,24 @@ export class CommandToXRPMgr {
423423 } ;
424424 for ( const dir of wipeDirs ) {
425425 if ( urls . some ( ( [ dest ] ) => destStartsWithDir ( dest , dir ) ) ) {
426- await this . deleteFileOrDir ( dir ) ;
426+ // Skip the per-delete FS-tree walk; getOnBoardFSTree() runs once at the end.
427+ await this . deleteFileOrDir ( dir , false ) ;
427428 }
428429 }
429430
431+ // Build each unique destination directory once instead of once per file.
432+ const uniqueDirs = new Set < string > ( ) ;
433+ for ( const [ deviceDest ] of urls ) {
434+ uniqueDirs . add ( deviceDest . substring ( 0 , deviceDest . lastIndexOf ( '/' ) ) ) ;
435+ }
436+ for ( const dir of uniqueDirs ) {
437+ await this . buildPath ( dir ) ;
438+ }
439+
430440 for ( let i = 0 ; i < urls . length ; i ++ ) {
431441 const [ deviceDest , sourceRel ] = urls [ i ] ;
432442 const fetchUrl = resolveSourceUrl ( sourceRel ) + '?version=' + cacheToken ;
433- await this . uploadFile ( deviceDest , await this . downloadFile ( fetchUrl ) ) ;
443+ await this . uploadFile ( deviceDest , await this . downloadFile ( fetchUrl ) , false , false ) ;
434444 emitProgress ( cur_percent ) ;
435445 cur_percent += percent_per ;
436446 }
@@ -764,13 +774,15 @@ export class CommandToXRPMgr {
764774 }
765775
766776
767- async uploadFile ( filePath : string , fileContents : string | Uint8Array , usePercent : boolean = false ) {
777+ async uploadFile ( filePath : string , fileContents : string | Uint8Array , usePercent : boolean = false , ensurePath : boolean = true ) {
768778 if ( this . BUSY == true ) {
769779 return true ;
770780 }
771781
772- const pathToFile = filePath . substring ( 0 , filePath . lastIndexOf ( '/' ) ) ;
773- await this . buildPath ( pathToFile ) ;
782+ if ( ensurePath ) {
783+ const pathToFile = filePath . substring ( 0 , filePath . lastIndexOf ( '/' ) ) ;
784+ await this . buildPath ( pathToFile ) ;
785+ }
774786
775787 this . BUSY = true ;
776788 if ( usePercent )
@@ -962,7 +974,7 @@ export class CommandToXRPMgr {
962974
963975
964976 // Given a path, delete it on XRP
965- async deleteFileOrDir ( path : string ) {
977+ async deleteFileOrDir ( path : string , refreshTree : boolean = true ) {
966978 if ( path != undefined ) {
967979 if ( this . BUSY == true ) {
968980 return ;
@@ -996,7 +1008,9 @@ export class CommandToXRPMgr {
9961008 this . BUSY = false ;
9971009
9981010 // Make sure to update the filesystem after modifying it
999- await this . getOnBoardFSTree ( ) ;
1011+ if ( refreshTree ) {
1012+ await this . getOnBoardFSTree ( ) ;
1013+ }
10001014 //window.setPercent?.(100); TODO:
10011015 //window.resetPercentDelay?.();
10021016 }
0 commit comments