@@ -794,7 +794,7 @@ export abstract class BasePHP implements IsomorphicLocalPHP {
794
794
// Copy the MEMFS directory structure from the old FS to the new one
795
795
if ( this . requestHandler ) {
796
796
const docroot = this . documentRoot ;
797
- recreateMemFS ( this [ __private__dont__use ] . FS , oldFS , docroot ) ;
797
+ copyFS ( oldFS , this [ __private__dont__use ] . FS , docroot ) ;
798
798
}
799
799
}
800
800
@@ -830,14 +830,22 @@ export function normalizeHeaders(
830
830
831
831
type EmscriptenFS = any ;
832
832
833
+ export function syncFSTo ( source : BasePHP , target : BasePHP ) {
834
+ copyFS (
835
+ source [ __private__dont__use ] . FS ,
836
+ target [ __private__dont__use ] . FS ,
837
+ source . documentRoot
838
+ ) ;
839
+ }
840
+
833
841
/**
834
842
* Copies the MEMFS directory structure from one FS in another FS.
835
843
* Non-MEMFS nodes are ignored.
836
844
*/
837
- function recreateMemFS ( newFS : EmscriptenFS , oldFS : EmscriptenFS , path : string ) {
845
+ function copyFS ( source : EmscriptenFS , target : EmscriptenFS , path : string ) {
838
846
let oldNode ;
839
847
try {
840
- oldNode = oldFS . lookupPath ( path ) ;
848
+ oldNode = source . lookupPath ( path ) ;
841
849
} catch ( e ) {
842
850
return ;
843
851
}
@@ -850,23 +858,23 @@ function recreateMemFS(newFS: EmscriptenFS, oldFS: EmscriptenFS, path: string) {
850
858
// Let's be extra careful and only proceed if newFs doesn't
851
859
// already have a node at the given path.
852
860
try {
853
- newFS = newFS . lookupPath ( path ) ;
861
+ target = target . lookupPath ( path ) ;
854
862
return ;
855
863
} catch ( e ) {
856
864
// There's no such node in the new FS. Good,
857
865
// we may proceed.
858
866
}
859
867
860
- if ( ! oldFS . isDir ( oldNode . node . mode ) ) {
861
- newFS . writeFile ( path , oldFS . readFile ( path ) ) ;
868
+ if ( ! source . isDir ( oldNode . node . mode ) ) {
869
+ target . writeFile ( path , source . readFile ( path ) ) ;
862
870
return ;
863
871
}
864
872
865
- newFS . mkdirTree ( path ) ;
866
- const filenames = oldFS
873
+ target . mkdirTree ( path ) ;
874
+ const filenames = source
867
875
. readdir ( path )
868
876
. filter ( ( name : string ) => name !== '.' && name !== '..' ) ;
869
877
for ( const filename of filenames ) {
870
- recreateMemFS ( newFS , oldFS , joinPaths ( path , filename ) ) ;
878
+ copyFS ( source , target , joinPaths ( path , filename ) ) ;
871
879
}
872
880
}
0 commit comments