Skip to content

Commit 391915e

Browse files
committed
chore: revert atomic install (#2534)
This reverts 2 commits: - "fix(installer): create tmp directory inside `browserPath` (#2498)" commit 946b4ef. - "feat: support atomic installation of browsers (#2489)" commit 3de0c08. This addresses installation issues we see in some CI environments.
1 parent 93f287c commit 391915e

File tree

3 files changed

+11
-43
lines changed

3 files changed

+11
-43
lines changed

src/install/browserFetcher.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import * as extract from 'extract-zip';
1919
import * as fs from 'fs';
2020
import * as ProxyAgent from 'https-proxy-agent';
21+
import * as os from 'os';
22+
import * as path from 'path';
2123
import * as ProgressBar from 'progress';
2224
import { getProxyForUrl } from 'proxy-from-env';
2325
import * as URL from 'url';
@@ -28,7 +30,6 @@ import { BrowserName, BrowserPlatform, BrowserDescriptor } from './browserPaths'
2830

2931
const unlinkAsync = util.promisify(fs.unlink.bind(fs));
3032
const chmodAsync = util.promisify(fs.chmod.bind(fs));
31-
const renameAsync = util.promisify(fs.rename.bind(fs));
3233
const existsAsync = (path: string): Promise<boolean> => new Promise(resolve => fs.stat(path, err => resolve(!err)));
3334

3435
export type OnProgressCallback = (downloadedBytes: number, totalBytes: number) => void;
@@ -106,13 +107,11 @@ export async function downloadBrowserWithProgressBar(browserPath: string, browse
106107
}
107108

108109
const url = revisionURL(browser);
109-
const zipPath = browserPaths.browserZipFile(browserPath, browser);
110+
const zipPath = path.join(os.tmpdir(), `playwright-download-${browser.name}-${browserPaths.hostPlatform}-${browser.revision}.zip`);
110111
try {
111112
await downloadFile(url, zipPath, progress);
112-
const extractPath = browserPaths.browserExtractDirectory(browserPath, browser);
113-
await extract(zipPath, { dir: extractPath});
114-
await chmodAsync(browserPaths.executablePath(extractPath, browser)!, 0o755);
115-
await renameAsync(extractPath, browserPath);
113+
await extract(zipPath, { dir: browserPath});
114+
await chmodAsync(browserPaths.executablePath(browserPath, browser)!, 0o755);
116115
} catch (e) {
117116
process.exitCode = 1;
118117
throw e;

src/install/browserPaths.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,7 @@ export function browserDirectory(browsersPath: string, browser: BrowserDescripto
104104
return path.join(browsersPath, `${browser.name}-${browser.revision}`);
105105
}
106106

107-
export function isBrowserDirectory(aPath: string): boolean {
108-
const baseName = path.basename(aPath);
107+
export function isBrowserDirectory(browserPath: string): boolean {
108+
const baseName = path.basename(browserPath);
109109
return baseName.startsWith('chromium-') || baseName.startsWith('firefox-') || baseName.startsWith('webkit-');
110110
}
111-
112-
const BROWSER_EXTRACT_DIRECTORY_PREFIX = 'playwright-extract-';
113-
114-
export function isBrowserExtractDirectory(aPath: string): boolean {
115-
const baseName = path.basename(aPath);
116-
return baseName.startsWith(BROWSER_EXTRACT_DIRECTORY_PREFIX);
117-
}
118-
119-
export function browserExtractDirectory(browserPath: string, browser: BrowserDescriptor): string {
120-
return (path.join(path.dirname(browserPath), `${BROWSER_EXTRACT_DIRECTORY_PREFIX}${browser.name}-${hostPlatform}-${browser.revision}`));
121-
}
122-
123-
const BROWSER_ZIP_FILE_PREFIX = 'playwright-download-';
124-
125-
export function isBrowserZipFile(aPath: string): boolean {
126-
const baseName = path.basename(aPath);
127-
return baseName.startsWith(BROWSER_ZIP_FILE_PREFIX) && baseName.endsWith('.zip');
128-
}
129-
130-
export function browserZipFile(browserPath: string, browser: BrowserDescriptor): string {
131-
return path.join(path.dirname(browserPath), `${BROWSER_ZIP_FILE_PREFIX}${browser.name}-${hostPlatform}-${browser.revision}.zip`);
132-
}

src/install/installer.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const fsReaddirAsync = util.promisify(fs.readdir.bind(fs));
2828
const fsReadFileAsync = util.promisify(fs.readFile.bind(fs));
2929
const fsUnlinkAsync = util.promisify(fs.unlink.bind(fs));
3030
const fsWriteFileAsync = util.promisify(fs.writeFile.bind(fs));
31-
const rmAsync = util.promisify(removeFolder);
31+
const removeFolderAsync = util.promisify(removeFolder);
3232

3333
export async function installBrowsersWithProgressBar(packagePath: string) {
3434
const browsersPath = browserPaths.browsersPath(packagePath);
@@ -60,27 +60,18 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
6060
}
6161
}
6262

63-
// 2. Delete all stale browser extract directories and .zip files.
64-
// NOTE: this must not run concurrently with other installations.
65-
let staleFiles = (await fsReaddirAsync(browsersPath)).map(file => path.join(browsersPath, file));
66-
staleFiles = staleFiles.filter(file => browserPaths.isBrowserZipFile(file) || browserPaths.isBrowserExtractDirectory(file));
67-
for (const staleFile of staleFiles) {
68-
logPolitely('Removing leftover from interrupted installation ' + staleFile);
69-
await rmAsync(staleFile).catch(e => {});
70-
}
71-
72-
// 3. Delete all unused browsers.
63+
// 2. Delete all unused browsers.
7364
let downloadedBrowsers = (await fsReaddirAsync(browsersPath)).map(file => path.join(browsersPath, file));
7465
downloadedBrowsers = downloadedBrowsers.filter(file => browserPaths.isBrowserDirectory(file));
7566
const directories = new Set<string>(downloadedBrowsers);
7667
for (const browser of allBrowsers)
7768
directories.delete(browserPaths.browserDirectory(browsersPath, browser));
7869
for (const directory of directories) {
7970
logPolitely('Removing unused browser at ' + directory);
80-
await rmAsync(directory).catch(e => {});
71+
await removeFolderAsync(directory).catch(e => {});
8172
}
8273

83-
// 4. Install missing browsers for this package.
74+
// 3. Install missing browsers for this package.
8475
const myBrowsers = JSON.parse((await fsReadFileAsync(path.join(packagePath, 'browsers.json'))).toString())['browsers'] as browserPaths.BrowserDescriptor[];
8576
for (const browser of myBrowsers) {
8677
const browserPath = browserPaths.browserDirectory(browsersPath, browser);

0 commit comments

Comments
 (0)