@@ -37,7 +37,7 @@ function Local(){
37
37
38
38
const binaryPath = this . getBinaryPath ( null , options [ 'bs-host' ] ) ;
39
39
that . binaryPath = binaryPath ;
40
- childProcess . exec ( 'echo "" > ' + that . logfile ) ;
40
+ fs . writeFileSync ( that . logfile , '' ) ;
41
41
that . opcode = 'start' ;
42
42
if ( ! this . binaryPath ) {
43
43
return new LocalError ( 'Couldn\'t find binary file' ) ;
@@ -86,9 +86,46 @@ function Local(){
86
86
87
87
this . getBinaryPath ( function ( binaryPath ) {
88
88
that . binaryPath = binaryPath ;
89
- childProcess . exec ( 'echo "" > ' + that . logfile ) ;
89
+ fs . writeFile ( that . logfile , '' , function ( err ) {
90
+ if ( err ) {
91
+ return callback ( new LocalError ( 'Failed to create log file: ' + err . message ) ) ;
92
+ }
93
+ that . opcode = 'start' ;
94
+ that . tunnel = childProcess . execFile ( that . binaryPath , that . getBinaryArgs ( ) , function ( error , stdout , stderr ) {
95
+ if ( error ) {
96
+ const binaryDownloadErrorMessage = `Error while trying to execute binary: ${ util . format ( error ) } ` ;
97
+ console . error ( binaryDownloadErrorMessage ) ;
98
+ if ( that . retriesLeft > 0 ) {
99
+ console . log ( 'Retrying Binary Download. Retries Left' , that . retriesLeft ) ;
100
+ that . retriesLeft -= 1 ;
101
+ fs . unlinkSync ( that . binaryPath ) ;
102
+ delete ( that . binaryPath ) ;
103
+ process . env . BINARY_DOWNLOAD_ERROR_MESSAGE = binaryDownloadErrorMessage ;
104
+ process . env . BINARY_DOWNLOAD_FALLBACK_ENABLED = true ;
105
+ that . start ( options , callback ) ;
106
+ return ;
107
+ } else {
108
+ callback ( new LocalError ( error . toString ( ) ) ) ;
109
+ }
110
+ }
90
111
91
- that . opcode = 'start' ;
112
+ var data = { } ;
113
+ if ( stdout )
114
+ data = JSON . parse ( stdout ) ;
115
+ else if ( stderr )
116
+ data = JSON . parse ( stderr ) ;
117
+ else
118
+ callback ( new LocalError ( 'No output received' ) ) ;
119
+
120
+ if ( data [ 'state' ] != 'connected' ) {
121
+ callback ( new LocalError ( data [ 'message' ] [ 'message' ] ) ) ;
122
+ } else {
123
+ that . pid = data [ 'pid' ] ;
124
+ that . isProcessRunning = true ;
125
+ callback ( ) ;
126
+ }
127
+ } ) ;
128
+ } ) ;
92
129
that . tunnel = childProcess . execFile ( that . binaryPath , that . getBinaryArgs ( ) , function ( error , stdout , stderr ) {
93
130
if ( error ) {
94
131
const binaryDownloadErrorMessage = `Error while trying to execute binary: ${ util . format ( error ) } ` ;
0 commit comments