@@ -39,21 +39,7 @@ function LocalBinary(){
3939
4040 this . httpPath = this . getDownloadPath ( ) ;
4141
42- this . retryBinaryDownloadSync = function ( conf , destParentDir , retries , binaryPath ) {
43- var that = this ;
44- if ( retries > 0 ) {
45- console . log ( 'Retrying Download. Retries left' , retries ) ;
46- try {
47- const stats = fs . statSync ( binaryPath )
48- fs . unlinkSync ( binaryPath ) ;
49- } catch ( er ) { }
50-
51- that . downloadSync ( conf , destParentDir , retries - 1 )
5242
53- } else {
54- console . error ( 'Number of retries to download exceeded.' ) ;
55- }
56- }
5743
5844 this . retryBinaryDownload = function ( conf , destParentDir , callback , retries , binaryPath ) {
5945 var that = this ;
@@ -63,7 +49,7 @@ function LocalBinary(){
6349 if ( err == null ) {
6450 fs . unlinkSync ( binaryPath ) ;
6551 }
66- that . download ( conf , destParentDir , callback , retries - 1 ) ;
52+ return callback ? that . download ( conf , destParentDir , callback , retries - 1 ) : that . downloadSync ( conf , destParentDir , retries - 1 ) ;
6753 } ) ;
6854 } else {
6955 console . error ( 'Number of retries to download exceeded.' ) ;
@@ -118,19 +104,19 @@ function LocalBinary(){
118104 }
119105 if ( output . includes ( 'failed' ) ) {
120106 console . log ( 'failed to download' ) ;
121- that . retryBinaryDownloadSync ( conf , destParentDir , retries , binaryPath ) ;
107+ return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
122108 } else {
123109 if ( fs . existsSync ( binaryPath ) ) {
124110 fs . chmodSync ( binaryPath , '0755' )
125111 return binaryPath ;
126112 } else {
127113 console . log ( 'failed to download' ) ;
128- that . retryBinaryDownloadSync ( conf , destParentDir , retries , binaryPath ) ;
114+ return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
129115 }
130116 }
131117 } catch ( err ) {
132118 console . log ( 'Download failed with error' , err ) ;
133- that . retryBinaryDownloadSync ( conf , destParentDir , retries , binaryPath ) ;
119+ return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
134120 }
135121 }
136122
@@ -172,25 +158,14 @@ function LocalBinary(){
172158 } ) ;
173159 } ;
174160
175- this . binaryPathSync = function ( conf ) {
176- var destParentDir = this . getAvailableDirs ( ) ;
177- var destBinaryName = ( this . windows ) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal' ;
178- var binaryPath = path . join ( destParentDir , destBinaryName ) ;
179- if ( this . checkPath ( binaryPath , fs . X_OK ) ) {
180- return binaryPath ;
181- } else {
182- return this . downloadSync ( conf , destParentDir , 5 ) ;
183- }
184- }
185-
186161 this . binaryPath = function ( conf , callback ) {
187162 var destParentDir = this . getAvailableDirs ( ) ;
188163 var destBinaryName = ( this . windows ) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal' ;
189164 var binaryPath = path . join ( destParentDir , destBinaryName ) ;
190165 if ( this . checkPath ( binaryPath , fs . X_OK ) ) {
191- callback ( binaryPath ) ;
166+ return callback ? callback ( binaryPath ) : binaryPath ;
192167 } else {
193- this . download ( conf , destParentDir , callback , 5 ) ;
168+ return callback ? this . download ( conf , destParentDir , callback , 5 ) : this . downloadSync ( conf , destParentDir , 5 ) ;
194169 }
195170 } ;
196171
0 commit comments