From 136c2f86960b32f67328ba58f1cab61baeb4ef16 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 22 Jul 2016 11:56:25 -0400 Subject: [PATCH] Don't let previous extraction attempts interfere with later ones. --- tools/fs/files.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/fs/files.js b/tools/fs/files.js index 92bd21ef42..932c0da78b 100644 --- a/tools/fs/files.js +++ b/tools/fs/files.js @@ -727,7 +727,15 @@ files.extractTarGz = function (buffer, destPath, options) { files.rmdir(tempDir); }; +function ensureDirectoryEmpty(dir) { + files.readdir(dir).forEach(file => { + files.rm_recursive(files.pathJoin(dir, file)); + }); +} + function tryExtractWithNativeTar(buffer, tempDir) { + ensureDirectoryEmpty(tempDir); + const tarProc = spawn("tar", ["xzf", "-"], { cwd: tempDir, stdio: "pipe" @@ -743,6 +751,8 @@ function tryExtractWithNativeTar(buffer, tempDir) { } function tryExtractWithNative7z(buffer, tempDir) { + ensureDirectoryEmpty(tempDir); + const exeOSPath = files.convertToOSPath( files.pathJoin(files.getCurrentNodeBinDir(), "7z.exe")); const tarGzBasename = "out.tar.gz"; @@ -796,6 +806,8 @@ function tryExtractWithNative7z(buffer, tempDir) { } function tryExtractWithNpmTar(buffer, tempDir) { + ensureDirectoryEmpty(tempDir); + var tar = require("tar"); var zlib = require("zlib");