Skip to content

Commit

Permalink
feat: support atomic installation of browsers (#2489)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aslushnikov authored Jun 5, 2020
1 parent 28e0ce1 commit 3de0c08
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/install/browserFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3de0c08

Please sign in to comment.