Skip to content

Commit

Permalink
Fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Dec 11, 2019
1 parent d4b6d6a commit f3dac42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 1.2.4 | 2019-12-11

- Allow running offline when `version` is specified and a matching version is found locally. #51.
- Show error when failing to unzip downloaded vscode archive. #50.

### 1.2.3 | 2019-10-31

Expand Down
15 changes: 11 additions & 4 deletions lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ function unzipVSCode(vscodeArchivePath: string) {
const dirName = path.parse(vscodeArchivePath).name;
const extractDir = path.resolve(vscodeTestDir, dirName);

let res: cp.SpawnSyncReturns<string>;
if (vscodeArchivePath.endsWith('.zip')) {
if (process.platform === 'win32') {
cp.spawnSync('powershell.exe', [
res = cp.spawnSync('powershell.exe', [
'-NoProfile',
'-ExecutionPolicy', 'Bypass',
'-NonInteractive',
Expand All @@ -109,14 +110,18 @@ function unzipVSCode(vscodeArchivePath: string) {
`Microsoft.PowerShell.Archive\\Expand-Archive -Path "${vscodeArchivePath}" -DestinationPath "${extractDir}"`
]);
} else {
cp.spawnSync('unzip', [vscodeArchivePath, '-d', `${extractDir}`]);
res = cp.spawnSync('unzip', [vscodeArchivePath, '-d', `${extractDir}`]);
}
} else {
// tar does not create extractDir by default
if (!fs.existsSync(extractDir)) {
fs.mkdirSync(extractDir);
}
cp.spawnSync('tar', ['-xzf', vscodeArchivePath, '-C', extractDir]);
res = cp.spawnSync('tar', ['-xzf', vscodeArchivePath, '-C', extractDir]);
}

if (res && !(res.status === 0 && res.signal === null)) {
throw Error(`Failed to unzip downloaded vscode at ${vscodeArchivePath}`);
}
}

Expand Down Expand Up @@ -169,7 +174,8 @@ export async function downloadAndUnzipVSCode(version?: DownloadVersion): Promise
await del.rmdir(downloadedPath);
console.log(`Removed ${downloadedPath}`);
} catch (err) {
console.log(`Failed to remove outdated Insiders at ${downloadedPath}.`);
console.error(err);
throw Error(`Failed to remove outdated Insiders at ${downloadedPath}.`);
}
}
} else {
Expand All @@ -188,6 +194,7 @@ export async function downloadAndUnzipVSCode(version?: DownloadVersion): Promise
fs.unlinkSync(vscodeArchivePath);
}
} catch (err) {
console.error(err);
throw Error(`Failed to download and unzip VS Code ${version}`);
}

Expand Down

0 comments on commit f3dac42

Please sign in to comment.