@@ -18,8 +18,6 @@ import {
18
18
virtualFs ,
19
19
} from '@angular-devkit/core' ;
20
20
import { ParseError , parse as jsoncParse , printParseErrorCode } from 'jsonc-parser' ;
21
- import { EMPTY , Observable , concatMap , map , mergeMap } from 'rxjs' ;
22
- import { TextDecoder } from 'util' ;
23
21
import {
24
22
ContentHasMutatedException ,
25
23
FileAlreadyExistException ,
@@ -496,38 +494,39 @@ export class FilterHostTree extends HostTree {
496
494
// cast to allow access
497
495
const originalBackend = ( tree as FilterHostTree ) . _backend ;
498
496
499
- const recurse : ( base : Path ) => Observable < void > = ( base ) => {
500
- return originalBackend . list ( base ) . pipe (
501
- mergeMap ( ( x ) => x ) ,
502
- map ( ( path ) => join ( base , path ) ) ,
503
- concatMap ( ( path ) => {
504
- let isDirectory = false ;
505
- originalBackend . isDirectory ( path ) . subscribe ( ( val ) => ( isDirectory = val ) ) ;
506
- if ( isDirectory ) {
507
- return recurse ( path ) ;
508
- }
509
-
510
- let isFile = false ;
511
- originalBackend . isFile ( path ) . subscribe ( ( val ) => ( isFile = val ) ) ;
512
- if ( ! isFile || ! filter ( path ) ) {
513
- return EMPTY ;
514
- }
497
+ // Walk the original backend and add files that match the filter to the new backend
498
+ const pendingPaths : Path [ ] = [ '/' as Path ] ;
499
+ while ( pendingPaths . length > 0 ) {
500
+ const currentPath = pendingPaths . pop ( ) ;
501
+ if ( currentPath === undefined ) {
502
+ break ;
503
+ }
515
504
516
- let content : ArrayBuffer | null = null ;
517
- originalBackend . read ( path ) . subscribe ( ( val ) => ( content = val ) ) ;
518
- if ( ! content ) {
519
- return EMPTY ;
520
- }
505
+ let isDirectory = false ;
506
+ originalBackend . isDirectory ( currentPath ) . subscribe ( ( val ) => ( isDirectory = val ) ) ;
507
+ if ( isDirectory ) {
508
+ originalBackend
509
+ . list ( currentPath )
510
+ . subscribe ( ( val ) => pendingPaths . push ( ...val . map ( ( p ) => join ( currentPath , p ) ) ) ) ;
511
+ continue ;
512
+ }
521
513
522
- return newBackend . write ( path , content as { } as virtualFs . FileBuffer ) ;
523
- } ) ,
524
- ) ;
525
- } ;
514
+ let isFile = false ;
515
+ originalBackend . isFile ( currentPath ) . subscribe ( ( val ) => ( isFile = val ) ) ;
516
+ if ( ! isFile || ! filter ( currentPath ) ) {
517
+ continue ;
518
+ }
526
519
527
- recurse ( normalize ( '/' ) ) . subscribe ( ) ;
520
+ let content = null ;
521
+ originalBackend . read ( currentPath ) . subscribe ( ( val ) => ( content = val ) ) ;
522
+ if ( content !== null ) {
523
+ newBackend . write ( currentPath , content ) . subscribe ( ) ;
524
+ }
525
+ }
528
526
529
527
super ( newBackend ) ;
530
528
529
+ // Add actions that match the filter to new tree
531
530
for ( const action of tree . actions ) {
532
531
if ( ! filter ( action . path ) ) {
533
532
continue ;
0 commit comments