Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(archive): extract without overwriting existing files
Browse files Browse the repository at this point in the history
  • Loading branch information
evshiron committed Mar 22, 2017
1 parent fe7e58a commit 34579b7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -8,8 +8,7 @@
"run": "./dist/bin/run.js"
},
"scripts": {
"pretest": "npm run build",
"test": "ava --verbose",
"test": "npm run build && ava",
"coverage": "nyc ava",
"build": "tsc",
"release": "npm test && standard-version"
Expand Down
12 changes: 6 additions & 6 deletions src/lib/Builder.ts
Expand Up @@ -313,7 +313,7 @@ export class Builder {

}

protected async integrateFFmpeg(platform: string, arch: string, runtimeDir: string, pkg: any, config: BuildConfig) {
protected async integrateFFmpeg(platform: string, arch: string, targetDir: string, pkg: any, config: BuildConfig) {

const downloader = new FFmpegDownloader({
platform, arch,
Expand All @@ -333,7 +333,7 @@ export class Builder {
const ffmpegDir = await downloader.fetchAndExtract();

const src = await findFFmpeg(platform, ffmpegDir);
const dest = await findFFmpeg(platform, runtimeDir);
const dest = await findFFmpeg(platform, targetDir);

await copyAsync(src, dest);

Expand Down Expand Up @@ -364,6 +364,10 @@ export class Builder {

await copyAsync(runtimeRoot, targetDir);

if(config.ffmpegIntegration) {
await this.integrateFFmpeg(platform, arch, targetDir, pkg, config);
}

await ensureDirAsync(appRoot);

// Copy before refining might void the effort.
Expand Down Expand Up @@ -433,10 +437,6 @@ export class Builder {

const runtimeDir = await downloader.fetchAndExtract();

if(config.ffmpegIntegration) {
await this.integrateFFmpeg(platform, arch, runtimeDir, pkg, config);
}

if(!this.options.mute) {
console.info('Building directory target...');
}
Expand Down
9 changes: 8 additions & 1 deletion src/lib/Runner.ts
Expand Up @@ -79,7 +79,14 @@ export class Runner {
const runtimeDir = await downloader.fetchAndExtract();

if(config.ffmpegIntegration) {
await this.integrateFFmpeg(platform, arch, runtimeDir, pkg, config);

// FIXME: Integrate without overwriting extracted files.
//await this.integrateFFmpeg(platform, arch, runtimeDir, pkg, config);

if(!this.options.mute) {
console.warn('Running with FFmpeg integration is not supported.');
}

}

const executable = await findExecutable(platform, runtimeDir);
Expand Down
22 changes: 16 additions & 6 deletions src/lib/archive.ts
Expand Up @@ -8,12 +8,18 @@ const debug = require('debug')('build:archive');

import { tmpFile, spawnAsync } from './util';

async function extract(archive: string, dest: string = dirname(archive)) {
interface IExtractOptions {
overwrite: boolean;
}

async function extract(archive: string, dest: string = dirname(archive), options: IExtractOptions = {
overwrite: false,
}) {

debug('in extract', 'archive', archive);
debug('in extract', 'dest', dest);

const { code, signal } = await spawnAsync(path7za, [ 'x', '-y', `-o${ resolve(dest) }`, resolve(archive) ]);
const { code, signal } = await spawnAsync(path7za, [ 'x', '-y', `-ao${ options.overwrite ? 'a' : 's' }`, `-o${ resolve(dest) }`, resolve(archive) ]);

if(code == 2) {
throw new Error(`ERROR_PATH_NOT_FOUND path = ${ archive }`);
Expand All @@ -27,7 +33,9 @@ async function extract(archive: string, dest: string = dirname(archive)) {

}

async function extractTarGz(archive: string, dest: string = dirname(archive)) {
async function extractTarGz(archive: string, dest: string = dirname(archive), options: IExtractOptions = {
overwrite: false,
}) {

await extract(archive, dest);

Expand All @@ -41,13 +49,15 @@ async function extractTarGz(archive: string, dest: string = dirname(archive)) {

}

export async function extractGeneric(archive: string, dest: string = dirname(archive)) {
export async function extractGeneric(archive: string, dest: string = dirname(archive), options: IExtractOptions = {
overwrite: false,
}) {

if(archive.endsWith('.zip')) {
await extract(archive, dest);
await extract(archive, dest, options);
}
else if(archive.endsWith('tar.gz')) {
await extractTarGz(archive, dest);
await extractTarGz(archive, dest, options);
}
else {
throw new Error('ERROR_UNKNOWN_EXTENSION');
Expand Down

0 comments on commit 34579b7

Please sign in to comment.