Procházet zdrojové kódy

fix(archive): extract without overwriting existing files

evshiron před 8 roky
rodič
revize
34579b75b9
4 změnil soubory, kde provedl 31 přidání a 15 odebrání
  1. 1 2
      package.json
  2. 6 6
      src/lib/Builder.ts
  3. 8 1
      src/lib/Runner.ts
  4. 16 6
      src/lib/archive.ts

+ 1 - 2
package.json

@@ -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"

+ 6 - 6
src/lib/Builder.ts

@@ -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,
@@ -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);
 
@@ -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.
@@ -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...');
         }

+ 8 - 1
src/lib/Runner.ts

@@ -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);

+ 16 - 6
src/lib/archive.ts

@@ -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 }`);
@@ -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);
 
@@ -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');