@@ -39,21 +39,7 @@ function LocalBinary(){
39
39
40
40
this . httpPath = this . getDownloadPath ( ) ;
41
41
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 )
52
42
53
- } else {
54
- console . error ( 'Number of retries to download exceeded.' ) ;
55
- }
56
- }
57
43
58
44
this . retryBinaryDownload = function ( conf , destParentDir , callback , retries , binaryPath ) {
59
45
var that = this ;
@@ -63,7 +49,7 @@ function LocalBinary(){
63
49
if ( err == null ) {
64
50
fs . unlinkSync ( binaryPath ) ;
65
51
}
66
- that . download ( conf , destParentDir , callback , retries - 1 ) ;
52
+ return callback ? that . download ( conf , destParentDir , callback , retries - 1 ) : that . downloadSync ( conf , destParentDir , retries - 1 ) ;
67
53
} ) ;
68
54
} else {
69
55
console . error ( 'Number of retries to download exceeded.' ) ;
@@ -118,19 +104,19 @@ function LocalBinary(){
118
104
}
119
105
if ( output . includes ( 'failed' ) ) {
120
106
console . log ( 'failed to download' ) ;
121
- that . retryBinaryDownloadSync ( conf , destParentDir , retries , binaryPath ) ;
107
+ return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
122
108
} else {
123
109
if ( fs . existsSync ( binaryPath ) ) {
124
110
fs . chmodSync ( binaryPath , '0755' )
125
111
return binaryPath ;
126
112
} else {
127
113
console . log ( 'failed to download' ) ;
128
- that . retryBinaryDownloadSync ( conf , destParentDir , retries , binaryPath ) ;
114
+ return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
129
115
}
130
116
}
131
117
} catch ( err ) {
132
118
console . log ( 'Download failed with error' , err ) ;
133
- that . retryBinaryDownloadSync ( conf , destParentDir , retries , binaryPath ) ;
119
+ return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
134
120
}
135
121
}
136
122
@@ -172,25 +158,14 @@ function LocalBinary(){
172
158
} ) ;
173
159
} ;
174
160
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
-
186
161
this . binaryPath = function ( conf , callback ) {
187
162
var destParentDir = this . getAvailableDirs ( ) ;
188
163
var destBinaryName = ( this . windows ) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal' ;
189
164
var binaryPath = path . join ( destParentDir , destBinaryName ) ;
190
165
if ( this . checkPath ( binaryPath , fs . X_OK ) ) {
191
- callback ( binaryPath ) ;
166
+ return callback ? callback ( binaryPath ) : binaryPath ;
192
167
} else {
193
- this . download ( conf , destParentDir , callback , 5 ) ;
168
+ return callback ? this . download ( conf , destParentDir , callback , 5 ) : this . downloadSync ( conf , destParentDir , 5 ) ;
194
169
}
195
170
} ;
196
171
0 commit comments