feat: support atomic installation of browsers (#2489)

Currently, Ctrl-C while extracting browser might yield users in
a bad place.

This patch extracts browsers in a temp directory that is later
moved to a installer registry.
This commit is contained in:
Andrey Lushnikov 2020-06-05 16:26:32 -07:00 committed by GitHub
parent 28e0ce1bb1
commit 3de0c087bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,8 @@ import { BrowserName, BrowserPlatform, BrowserDescriptor } from './browserPaths'
const unlinkAsync = util.promisify(fs.unlink.bind(fs));
const chmodAsync = util.promisify(fs.chmod.bind(fs));
const mkdtempAsync = util.promisify(fs.mkdtemp.bind(fs));
const renameAsync = util.promisify(fs.rename.bind(fs));
const existsAsync = (path: string): Promise<boolean> => new Promise(resolve => fs.stat(path, err => resolve(!err)));
export type OnProgressCallback = (downloadedBytes: number, totalBytes: number) => void;
@ -110,8 +112,10 @@ export async function downloadBrowserWithProgressBar(browserPath: string, browse
const zipPath = path.join(os.tmpdir(), `playwright-download-${browser.name}-${browserPaths.hostPlatform}-${browser.revision}.zip`);
try {
await downloadFile(url, zipPath, progress);
await extract(zipPath, { dir: browserPath});
await chmodAsync(browserPaths.executablePath(browserPath, browser)!, 0o755);
const extractPath = await mkdtempAsync(path.join(os.tmpdir(), `playwright-extract-${browser.name}-${browserPaths.hostPlatform}-${browser.revision}-`));
await extract(zipPath, { dir: extractPath});
await chmodAsync(browserPaths.executablePath(extractPath, browser)!, 0o755);
await renameAsync(extractPath, browserPath);
} catch (e) {
process.exitCode = 1;
throw e;