Skip to content

Commit

Permalink
fix(browserfetcher): Fix windows fetching (#3256)
Browse files Browse the repository at this point in the history
Since r591479 windows archives are uploaded with a different
name.
  • Loading branch information
aslushnikov committed Sep 17, 2018
1 parent f5d388a commit 7f00860
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions lib/BrowserFetcher.js
Expand Up @@ -28,13 +28,42 @@ const ProxyAgent = require('https-proxy-agent');
const getProxyForUrl = require('proxy-from-env').getProxyForUrl;

const DEFAULT_DOWNLOAD_HOST = 'https://storage.googleapis.com';

const supportedPlatforms = ['mac', 'linux', 'win32', 'win64'];
const downloadURLs = {
linux: '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip',
mac: '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip',
win32: '%s/chromium-browser-snapshots/Win/%d/chrome-win32.zip',
win64: '%s/chromium-browser-snapshots/Win_x64/%d/chrome-win32.zip',
linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',
mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',
win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip',
win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
};

/**
* @param {string} platform
* @param {string} revision
* @return {string}
*/
function archiveName(platform, revision) {
if (platform === 'linux')
return 'chrome-linux';
if (platform === 'mac')
return 'chrome-mac';
if (platform === 'win32' || platform === 'win64') {
// Windows archive name changed at r591479.
return parseInt(revision, 10) > 591479 ? 'chrome-win' : 'chrome-win32';
}
return null;
}

/**
* @param {string} platform
* @param {string} host
* @param {string} revision
* @return {string}
*/
function downloadURL(platform, host, revision) {
return util.format(downloadURLs[platform], host, revision, archiveName(platform, revision));
}

const readdirAsync = helper.promisify(fs.readdir.bind(fs));
const mkdirAsync = helper.promisify(fs.mkdir.bind(fs));
const unlinkAsync = helper.promisify(fs.unlink.bind(fs));
Expand Down Expand Up @@ -66,7 +95,6 @@ class BrowserFetcher {
this._platform = os.arch() === 'x64' ? 'win64' : 'win32';
assert(this._platform, 'Unsupported platform: ' + os.platform());
}
const supportedPlatforms = ['mac', 'linux', 'win32', 'win64'];
assert(supportedPlatforms.includes(this._platform), 'Unsupported platform: ' + this._platform);
}

Expand All @@ -82,8 +110,7 @@ class BrowserFetcher {
* @return {!Promise<boolean>}
*/
canDownload(revision) {
const url = util.format(downloadURLs[this._platform], this._downloadHost, revision);

const url = downloadURL(this._platform, this._downloadHost, revision);
let resolve;
const promise = new Promise(x => resolve = x);
const request = httpRequest(url, 'HEAD', response => {
Expand All @@ -102,8 +129,7 @@ class BrowserFetcher {
* @return {!Promise<!BrowserFetcher.RevisionInfo>}
*/
async download(revision, progressCallback) {
let url = downloadURLs[this._platform];
url = util.format(url, this._downloadHost, revision);
const url = downloadURL(this._platform, this._downloadHost, revision);
const zipPath = path.join(this._downloadsFolder, `download-${this._platform}-${revision}.zip`);
const folderPath = this._getFolderPath(revision);
if (await existsAsync(folderPath))
Expand Down Expand Up @@ -151,15 +177,14 @@ class BrowserFetcher {
const folderPath = this._getFolderPath(revision);
let executablePath = '';
if (this._platform === 'mac')
executablePath = path.join(folderPath, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
executablePath = path.join(folderPath, archiveName(this._platform, revision), 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
else if (this._platform === 'linux')
executablePath = path.join(folderPath, 'chrome-linux', 'chrome');
executablePath = path.join(folderPath, archiveName(this._platform, revision), 'chrome');
else if (this._platform === 'win32' || this._platform === 'win64')
executablePath = path.join(folderPath, 'chrome-win32', 'chrome.exe');
executablePath = path.join(folderPath, archiveName(this._platform, revision), 'chrome.exe');
else
throw new Error('Unsupported platform: ' + this._platform);
let url = downloadURLs[this._platform];
url = util.format(url, this._downloadHost, revision);
const url = downloadURL(this._platform, this._downloadHost, revision);
const local = fs.existsSync(folderPath);
return {revision, executablePath, folderPath, local, url};
}
Expand All @@ -185,7 +210,7 @@ function parseFolderPath(folderPath) {
if (splits.length !== 2)
return null;
const [platform, revision] = splits;
if (!downloadURLs[platform])
if (!supportedPlatforms.includes(platform))
return null;
return {platform, revision};
}
Expand Down

0 comments on commit 7f00860

Please sign in to comment.