Skip to content

Commit c57a4f0

Browse files
authored
Merge pull request #851 from udarrr/main
checking downloaded local file with remote file by size/md5
2 parents bd04735 + a54be3e commit c57a4f0

File tree

5 files changed

+78
-25
lines changed

5 files changed

+78
-25
lines changed

lib/default-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = () => {
2727
},
2828
chromiumedge: {
2929
version: 'latest',
30-
fallbackVersion: '96.0.1054.34',
30+
fallbackVersion: '117.0.2045.55',
3131
arch: process.arch,
3232
onlyDriverArgs: [],
3333
baseURL: 'https://msedgedriver.azureedge.net',

lib/install-utils.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const yauzl = require('yauzl');
66
const fs = require('fs');
77
const zlib = require('zlib');
88
const got = require('got');
9-
const merge = require('lodash.merge');
109
const debug = require('debug')('selenium-standalone:install');
1110
const { logError } = require('./log-error');
11+
const md5 = require('md5');
1212

1313
const installers = ['selenium', 'chrome', 'ie', 'firefox', 'edge', 'chromiumedge'];
1414

@@ -79,30 +79,21 @@ async function setDriverFilePermissions(where) {
7979
}
8080
}
8181

82-
async function isUpToDate(url, requestOpts, etag) {
83-
if (!etag) {
82+
async function isUpToDate(url, file, pathToFile) {
83+
if (!file) {
8484
return false;
8585
}
86-
87-
const options = merge({}, requestOpts, {
88-
headers: {
89-
'If-None-Match': etag,
90-
},
91-
timeout: 2500,
92-
});
9386
try {
94-
const response = await got(url, options);
95-
return response.statusCode === 304;
96-
} catch (err) {
97-
if (err.response && err.response.statusCode === 304) {
87+
const response = await got.head(url, {
88+
timeout: 2500,
89+
});
90+
if (response.headers['content-length'] === `${fs.statSync(pathToFile).size}`) {
9891
return true;
9992
}
100-
logError(
101-
`Could not request headers from ${url}: ` +
102-
(err.response ? err.response.statusCode : err.message) +
103-
', continue without checking for latest version.'
104-
);
105-
return true;
93+
return response.headers.etag.includes(md5(file).toString());
94+
} catch (err) {
95+
logError(`Remote file size/hash in ${url} don't match with local file ${pathToFile}`);
96+
return false;
10697
}
10798
}
10899

lib/install.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,16 @@ async function install(_opts) {
121121
}
122122

123123
async function onlyInstallMissingFiles(opts) {
124-
let etag;
124+
let file;
125125
try {
126-
etag = await readFile(`${opts.to}.etag`);
126+
file = await readFile(opts.to);
127127
} catch (err) {
128128
// ENOENT means not found which is ok. But anything else re-raise
129-
if (err.code != 'ENOENT') throw err;
129+
if (err.code != 'ENOENT') {
130+
throw err;
131+
}
130132
}
131-
const isLatest = await isUpToDate(opts.from, requestOpts, etag);
133+
const isLatest = await isUpToDate(opts.from, file, opts.to);
132134

133135
// File already exists. Prevent download/installation.
134136
if (isLatest) {

package-lock.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"is-port-reachable": "^3.0.0",
5151
"lodash.mapvalues": "^4.6.0",
5252
"lodash.merge": "^4.6.2",
53+
"md5": "^2.3.0",
5354
"minimist": "^1.2.5",
5455
"mkdirp": "^2.1.3",
5556
"progress": "2.0.3",

0 commit comments

Comments
 (0)