Skip to content

Commit

Permalink
Fix extract on windows
Browse files Browse the repository at this point in the history
fbshipit-source-id: 9c3ff60
  • Loading branch information
jesseruder authored and expbot committed Feb 25, 2017
1 parent 3151042 commit 9359192
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@
* @flow
*/

import fs from 'fs';
import targz from 'tar.gz';
import path from 'path';
import spawnAsync from '@exponent/spawn-async';
import mkdirp from 'mkdirp';
import rimraf from 'rimraf';
import uuid from 'node-uuid';

import * as Binaries from './Binaries';
import UserSettings from './UserSettings';

async function _extractWindowsAsync(archive: string, dir: string) {
let dotExponentHomeDirectory = UserSettings.dotExponentHomeDirectory();
let tmpDir = path.join(dotExponentHomeDirectory, 'starter-app-cache', 'tmp');
let fileNameNoExtension;
if (archive.endsWith('.tar.gz')) {
fileNameNoExtension = path.basename(archive.substr(0, archive.length - '.tar.gz'.length));
} else {
fileNameNoExtension = path.basename(archive, path.extname(archive));
}
let tmpFile = path.join(tmpDir, `${fileNameNoExtension}.tar`);
let tmpDir = path.join(dotExponentHomeDirectory, 'tmp', uuid.v4());
mkdirp.sync(tmpDir);
let binary = path.join(Binaries.getBinariesPath(), '7z1602-extra', '7za');
try {
await spawnAsync(binary, ['x', archive, '-aoa', `-o${tmpDir}`]);
await spawnAsync(binary, ['x', tmpFile, '-aoa', `-o${dir}`]);
// We don't know the resulting filename after this step, so
// just assume the only file in the directory is our .tar file.
// This should be fine since we created the directory with a random name.
let files = fs.readdirSync(tmpDir);
let outputFile = path.resolve(tmpDir, files[0]);
await spawnAsync(binary, ['x', outputFile, '-aoa', `-o${dir}`]);
} catch (e) {
console.error(e.message);
console.error(e.stderr);
throw e;
} finally {
rimraf.sync(tmpDir);
}
}

Expand Down

0 comments on commit 9359192

Please sign in to comment.