@@ -63,6 +63,9 @@ class SfdcApi {
63
63
} ) ;
64
64
}
65
65
} else {
66
+ // Set Default value
67
+ self . conn . metadata . pollTimeout = 300000 ; // 5 mins
68
+
66
69
return resolve ( true ) ;
67
70
}
68
71
} ) ;
@@ -425,23 +428,11 @@ class SfdcApi {
425
428
if ( err ) return reject ( err ) ;
426
429
if ( result . success == 'true' ) {
427
430
self . logger ( '[SFDC] Retrieve metadata Done.' ) ;
428
- //self.logger('[SFDC] packagePath DecompressZip .' + packagePath + ' > ' + metaPath + ' > ' + (fs.existsSync (packagePath)));
431
+ // self.logger('[SFDC] packagePath DecompressZip .' + packagePath + ' > ' + metaPath + ' > ' + (fs.statSync (packagePath).size ));
429
432
if ( ! fs . existsSync ( packagePath ) ) return reject ( new Error ( 'Metadata zip not found' ) ) ;
430
- const unzipper = new DecompressZip ( packagePath )
431
- unzipper . on ( 'error' , function ( err ) {
432
- //self.logger('[SFDC] extract err.' + err);
433
+ self . extractMetaZip ( packagePath , metaPath , 0 , function ( err , success ) {
433
434
if ( err ) return reject ( err ) ;
434
- } ) ;
435
- unzipper . on ( 'extract' , function ( log ) {
436
- //self.logger('[SFDC]Finished extracting' + log);
437
- rimraf ( packagePath , function ( ) { } ) ;
438
- return resolve ( true ) ;
439
- } ) ;
440
- unzipper . extract ( {
441
- path : metaPath ,
442
- filter : function ( file ) {
443
- return file . type !== "SymbolicLink" ;
444
- }
435
+ return resolve ( success ) ;
445
436
} ) ;
446
437
} else {
447
438
return reject ( new Error ( 'Retrieve metadata failed' ) ) ;
@@ -450,6 +441,43 @@ class SfdcApi {
450
441
retrieveResult . stream ( ) . pipe ( zipstream ) ;
451
442
} ) ;
452
443
}
444
+
445
+ // Extract metadata zip file to src folder
446
+ // Metadata api may zip file cost sevaral ms
447
+ extractMetaZip ( sourceZipPath , targetPath , presize , callback ) {
448
+ const self = this ;
449
+ const fileinfo = fs . statSync ( sourceZipPath ) ;
450
+ if ( fileinfo . size == 0 ) {
451
+ // Is written
452
+ return setTimeout ( function ( ) {
453
+ self . extractMetaZip ( sourceZipPath , targetPath , presize , callback )
454
+ } , 500 ) ;
455
+ }
456
+ if ( presize !== fileinfo . size ) {
457
+ // Maybe written
458
+ presize = fileinfo . size ;
459
+ return setTimeout ( function ( ) {
460
+ self . extractMetaZip ( sourceZipPath , targetPath , presize , callback )
461
+ } , 500 ) ;
462
+ }
463
+ // Ready to extract
464
+ const unzipper = new DecompressZip ( sourceZipPath )
465
+ unzipper . on ( 'error' , function ( err ) {
466
+ // console.log('[SFDC] extract err.' + err);
467
+ if ( err ) return callback ( err ) ;
468
+ } ) ;
469
+ unzipper . on ( 'extract' , function ( log ) {
470
+ // console.log('[SFDC]Finished extracting' + log);
471
+ rimraf ( sourceZipPath , function ( ) { } ) ;
472
+ return callback ( null , true ) ;
473
+ } ) ;
474
+ unzipper . extract ( {
475
+ path : targetPath ,
476
+ filter : function ( file ) {
477
+ return file . type !== "SymbolicLink" ;
478
+ }
479
+ } ) ;
480
+ }
453
481
454
482
}
455
483
0 commit comments