mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
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:
parent
28e0ce1bb1
commit
3de0c087bc
@ -30,6 +30,8 @@ import { BrowserName, BrowserPlatform, BrowserDescriptor } from './browserPaths'
|
|||||||
|
|
||||||
const unlinkAsync = util.promisify(fs.unlink.bind(fs));
|
const unlinkAsync = util.promisify(fs.unlink.bind(fs));
|
||||||
const chmodAsync = util.promisify(fs.chmod.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)));
|
const existsAsync = (path: string): Promise<boolean> => new Promise(resolve => fs.stat(path, err => resolve(!err)));
|
||||||
|
|
||||||
export type OnProgressCallback = (downloadedBytes: number, totalBytes: number) => void;
|
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`);
|
const zipPath = path.join(os.tmpdir(), `playwright-download-${browser.name}-${browserPaths.hostPlatform}-${browser.revision}.zip`);
|
||||||
try {
|
try {
|
||||||
await downloadFile(url, zipPath, progress);
|
await downloadFile(url, zipPath, progress);
|
||||||
await extract(zipPath, { dir: browserPath});
|
const extractPath = await mkdtempAsync(path.join(os.tmpdir(), `playwright-extract-${browser.name}-${browserPaths.hostPlatform}-${browser.revision}-`));
|
||||||
await chmodAsync(browserPaths.executablePath(browserPath, browser)!, 0o755);
|
await extract(zipPath, { dir: extractPath});
|
||||||
|
await chmodAsync(browserPaths.executablePath(extractPath, browser)!, 0o755);
|
||||||
|
await renameAsync(extractPath, browserPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
throw e;
|
throw e;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user