[Downloader] Remove previous chromium revisions after roll
Currently, after the chromium was rolled to a new revision, the previsious revision is kept downloaded in the puppeteer folder. Since every revision is ~70Mb, it quickly piles up. This patch removes previous downloaded chromium revisions after a new one is successfully installed.
This commit is contained in:
parent
38e6f53cc7
commit
20fb1f6b9b
@ -22,15 +22,16 @@ let ProgressBar = require('progress');
|
|||||||
if (Downloader.revisionInfo(Downloader.currentPlatform(), revision))
|
if (Downloader.revisionInfo(Downloader.currentPlatform(), revision))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
let allRevisions = Downloader.downloadedRevisions();
|
||||||
Downloader.downloadRevision(Downloader.currentPlatform(), revision, onProgress)
|
Downloader.downloadRevision(Downloader.currentPlatform(), revision, onProgress)
|
||||||
.catch(error => {
|
// Remove previous chromium revisions.
|
||||||
console.error('Download failed: ' + error.message);
|
.then(() => Promise.all(allRevisions.map(({platform, revision}) => Downloader.removeRevision(platform, revision))))
|
||||||
});
|
.catch(error => console.error('Download failed: ' + error.message));
|
||||||
|
|
||||||
let progressBar = null;
|
let progressBar = null;
|
||||||
function onProgress(bytesTotal, delta) {
|
function onProgress(bytesTotal, delta) {
|
||||||
if (!progressBar) {
|
if (!progressBar) {
|
||||||
progressBar = new ProgressBar(`Downloading Chromium - ${toMegabytes(bytesTotal)} [:bar] :percent :etas `, {
|
progressBar = new ProgressBar(`Downloading Chromium r${revision} - ${toMegabytes(bytesTotal)} [:bar] :percent :etas `, {
|
||||||
complete: '=',
|
complete: '=',
|
||||||
incomplete: ' ',
|
incomplete: ' ',
|
||||||
width: 20,
|
width: 20,
|
||||||
|
@ -21,8 +21,9 @@ let path = require('path');
|
|||||||
let extract = require('extract-zip');
|
let extract = require('extract-zip');
|
||||||
let util = require('util');
|
let util = require('util');
|
||||||
let URL = require('url');
|
let URL = require('url');
|
||||||
|
let removeRecursive = require('rimraf');
|
||||||
|
|
||||||
let CHROMIUM_PATH = path.join(__dirname, '..', '.local-chromium');
|
let DOWNLOADS_FOLDER = path.join(__dirname, '..', '.local-chromium');
|
||||||
|
|
||||||
let downloadURLs = {
|
let downloadURLs = {
|
||||||
linux: 'https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip',
|
linux: 'https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip',
|
||||||
@ -89,13 +90,13 @@ module.exports = {
|
|||||||
let url = downloadURLs[platform];
|
let url = downloadURLs[platform];
|
||||||
console.assert(url, `Unsupported platform: ${platform}`);
|
console.assert(url, `Unsupported platform: ${platform}`);
|
||||||
url = util.format(url, revision);
|
url = util.format(url, revision);
|
||||||
let zipPath = path.join(CHROMIUM_PATH, `download-${platform}-${revision}.zip`);
|
let zipPath = path.join(DOWNLOADS_FOLDER, `download-${platform}-${revision}.zip`);
|
||||||
let folderPath = getFolderPath(platform, revision);
|
let folderPath = getFolderPath(platform, revision);
|
||||||
if (fs.existsSync(folderPath))
|
if (fs.existsSync(folderPath))
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(CHROMIUM_PATH))
|
if (!fs.existsSync(DOWNLOADS_FOLDER))
|
||||||
fs.mkdirSync(CHROMIUM_PATH);
|
fs.mkdirSync(DOWNLOADS_FOLDER);
|
||||||
await downloadFile(url, zipPath, progressCallback);
|
await downloadFile(url, zipPath, progressCallback);
|
||||||
await extractZip(zipPath, folderPath);
|
await extractZip(zipPath, folderPath);
|
||||||
} finally {
|
} finally {
|
||||||
@ -104,12 +105,32 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {!Array<!{platform:string, revision: string}>}
|
||||||
|
*/
|
||||||
|
downloadedRevisions: function() {
|
||||||
|
let fileNames = fs.readdirSync(DOWNLOADS_FOLDER);
|
||||||
|
return fileNames.map(fileName => parseFolderPath(fileName)).filter(revision => !!revision);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} platform
|
||||||
|
* @param {string} revision
|
||||||
|
*/
|
||||||
|
removeRevision: async function(platform, revision) {
|
||||||
|
console.assert(downloadURLs[platform], `Unsupported platform: ${platform}`);
|
||||||
|
const folderPath = getFolderPath(platform, revision);
|
||||||
|
console.assert(fs.existsSync(folderPath));
|
||||||
|
await new Promise(fulfill => removeRecursive(folderPath, fulfill));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} platform
|
* @param {string} platform
|
||||||
* @param {string} revision
|
* @param {string} revision
|
||||||
* @return {?{executablePath: string}}
|
* @return {?{executablePath: string}}
|
||||||
*/
|
*/
|
||||||
revisionInfo: function(platform, revision) {
|
revisionInfo: function(platform, revision) {
|
||||||
|
console.assert(downloadURLs[platform], `Unsupported platform: ${platform}`);
|
||||||
let folderPath = getFolderPath(platform, revision);
|
let folderPath = getFolderPath(platform, revision);
|
||||||
if (!fs.existsSync(folderPath))
|
if (!fs.existsSync(folderPath))
|
||||||
return null;
|
return null;
|
||||||
@ -130,11 +151,26 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} platform
|
* @param {string} platform
|
||||||
* @param {number} revision
|
* @param {string} revision
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
function getFolderPath(platform, revision) {
|
function getFolderPath(platform, revision) {
|
||||||
return path.join(CHROMIUM_PATH, platform + '-' + revision);
|
return path.join(DOWNLOADS_FOLDER, platform + '-' + revision);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} folderPath
|
||||||
|
* @return {?{platform: string, revision: string}}
|
||||||
|
*/
|
||||||
|
function parseFolderPath(folderPath) {
|
||||||
|
let name = path.basename(folderPath);
|
||||||
|
let splits = name.split('-');
|
||||||
|
if (splits.length !== 2)
|
||||||
|
return null;
|
||||||
|
let [platform, revision] = splits;
|
||||||
|
if (!downloadURLs[platform])
|
||||||
|
return null;
|
||||||
|
return {platform, revision};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user