Skip to content

Commit 9406107

Browse files
committed
add extra check to make sure the downloaded jar file is not corrupt
1 parent 8243197 commit 9406107

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/tunnel-launcher.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const async = require('async')
4+
const { exec } = require('child_process')
45
const fs = require('fs')
56
const os = require('os')
67
const path = require('path')
@@ -25,13 +26,24 @@ function download (options, callback) {
2526
}
2627

2728
try {
28-
const tunnelFile = fs.statSync(tunnelLocation)
29-
if (tunnelFile['size'] > 1024) {
30-
return callback(null)
29+
const exists = fs.existsSync(tunnelLocation)
30+
if (exists) {
31+
return exec(`java -jar ${tunnelLocation} -h`, (error, stdout, stderr) => {
32+
if (error || stderr) {
33+
logger('Found a cached testingbot-tunnel.jar file, but it might be corrupt. Redownloading.')
34+
downloadTunnel(url, tunnelLocation, callback)
35+
} else {
36+
callback(null)
37+
}
38+
})
3139
}
3240
} catch (ignore) {}
3341

34-
downloader.get(url, { fileName: 'testingbot-tunnel', destination: tunnelLocation }, (err, destination) => {
42+
return downloadTunnel(url, tunnelLocation, callback)
43+
}
44+
45+
function downloadTunnel (url, tunnelLocation, callback) {
46+
downloader.get(url, { fileName: 'testingbot-tunnel', destination: tunnelLocation }, (err) => {
3547
if (err) {
3648
return callback(new Error(`Could not download the tunnel from TestingBot - please check your connection. ${err.message}`))
3749
}

0 commit comments

Comments
 (0)