respect "prefix" field
This commit is contained in:
parent
a53821415f
commit
2c9bbf78eb
|
|
@ -16,6 +16,7 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { Writable, once } from 'stream';
|
import { Writable, once } from 'stream';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
enum TarType {
|
enum TarType {
|
||||||
REGTYPE,
|
REGTYPE,
|
||||||
|
|
@ -36,6 +37,7 @@ class TarEntry {
|
||||||
linkname: string;
|
linkname: string;
|
||||||
uid: number;
|
uid: number;
|
||||||
gid: number;
|
gid: number;
|
||||||
|
prefix: string;
|
||||||
|
|
||||||
fileStream: fs.WriteStream | null = null;
|
fileStream: fs.WriteStream | null = null;
|
||||||
remainingBytes = 0;
|
remainingBytes = 0;
|
||||||
|
|
@ -53,10 +55,11 @@ class TarEntry {
|
||||||
|
|
||||||
this.uid = parseInt(header.toString('ascii', 108, 116).trim(), 8);
|
this.uid = parseInt(header.toString('ascii', 108, 116).trim(), 8);
|
||||||
this.gid = parseInt(header.toString('ascii', 116, 124).trim(), 8);
|
this.gid = parseInt(header.toString('ascii', 116, 124).trim(), 8);
|
||||||
|
this.prefix = header.toString('utf8', 345, 500).replace(/\0/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
async writeToDisk(outputPath: (path: string) => string) {
|
async writeToDisk(outputPath: (path: string) => string) {
|
||||||
const fullPath = outputPath(this.name);
|
const fullPath = outputPath(this.prefix ? join(this.prefix, this.name) : this.name);
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case TarType.DIRTYPE:
|
case TarType.DIRTYPE:
|
||||||
await fs.promises.mkdir(fullPath, { recursive: true, mode: 0o755 });
|
await fs.promises.mkdir(fullPath, { recursive: true, mode: 0o755 });
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,11 @@ test('tar extractor', async () => {
|
||||||
expect(await readFile(test.info().outputPath('tar-example/symlink'), { encoding: 'utf-8' })).toEqual('foo-content');
|
expect(await readFile(test.info().outputPath('tar-example/symlink'), { encoding: 'utf-8' })).toEqual('foo-content');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('extract browser', async () => {
|
test.describe('browser downloads', () => {
|
||||||
// not run by default because it's not hermetic. i'll remove this once we use the TAR extractor in our code.
|
// not run by default because they're not hermetic. i'll remove them once we use the TAR extractor in our code.
|
||||||
test.skip(process.env.TEST_TAR_BROWSER !== '1');
|
test.skip(process.env.TEST_TAR_BROWSER !== '1');
|
||||||
|
|
||||||
|
test('chromium-headless-shell', async () => {
|
||||||
const response = await fetch('https://playwright.azureedge.net/download-for-internal-testing/playwright/builds/chromium/1152/chromium-headless-shell-linux-arm64.tar.br');
|
const response = await fetch('https://playwright.azureedge.net/download-for-internal-testing/playwright/builds/chromium/1152/chromium-headless-shell-linux-arm64.tar.br');
|
||||||
const input = Readable.fromWeb(response.body as any);
|
const input = Readable.fromWeb(response.body as any);
|
||||||
const decompressor = createBrotliDecompress();
|
const decompressor = createBrotliDecompress();
|
||||||
|
|
@ -117,4 +118,25 @@ test('extract browser', async () => {
|
||||||
'hyph-und-ethi.hyb',
|
'hyph-und-ethi.hyb',
|
||||||
'manifest.json',
|
'manifest.json',
|
||||||
]);
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('chromium-mac-arm64', async () => {
|
||||||
|
const response = await fetch('https://playwright.azureedge.net/download-for-internal-testing/playwright/builds/chromium/1152/chromium-mac-arm64.tar.br');
|
||||||
|
const input = Readable.fromWeb(response.body as any);
|
||||||
|
const decompressor = createBrotliDecompress();
|
||||||
|
const extractor = new TarExtractor(name => test.info().outputPath(name));
|
||||||
|
await finished(input.pipe(decompressor).pipe(extractor));
|
||||||
|
|
||||||
|
|
||||||
|
expect(await readdir(test.info().outputPath('chrome-mac'))).toEqual(['Chromium.app']);
|
||||||
|
expect(await readdir(test.info().outputPath('chrome-mac/Chromium.app'))).toEqual(['Contents']);
|
||||||
|
expect(await readdir(test.info().outputPath('chrome-mac/Chromium.app/Contents'))).toEqual([
|
||||||
|
'Frameworks',
|
||||||
|
'Info.plist',
|
||||||
|
'MacOS',
|
||||||
|
'PkgInfo',
|
||||||
|
'Resources',
|
||||||
|
]);
|
||||||
|
expect(await readFile(test.info().outputPath('chrome-mac/Chromium.app/Contents/Info.plist'), { encoding: 'utf-8' })).toHaveLength(10903);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue