From 0b06802a3daeef9826624342cf4fbd5c977933fd Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 22 May 2018 22:22:08 -0400 Subject: [PATCH] self updates are not available for windows --- src/commands/update.command.ts | 26 +++++++++++++++----------- src/program.ts | 2 ++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/commands/update.command.ts b/src/commands/update.command.ts index 8c48221098..3dab6869c8 100644 --- a/src/commands/update.command.ts +++ b/src/commands/update.command.ts @@ -56,30 +56,27 @@ export class UpdateCommand { } } - if (cmd.self || false) { + if ((cmd.self || false) && process.platform !== 'win32') { const zipResponse = await fetch.default(downloadUrl); if (zipResponse.status === 200) { + const currentDir = this.inPkg ? path.dirname(process.execPath) : __dirname; try { const zipBuffer = await zipResponse.buffer(); const zip = new AdmZip(zipBuffer); - const currentDir = this.inPkg ? path.dirname(process.execPath) : __dirname; let currentMode: number = null; - if (this.inPkg && process.platform !== 'win32') { + if (this.inPkg) { const stats = fs.statSync(process.execPath); currentMode = stats.mode; } zip.extractAllTo(currentDir, true); - if (process.platform !== 'win32') { - const bwFilePath = path.join(currentDir, 'bw'); - fs.chmodSync(bwFilePath, currentMode != null ? currentMode : '764'); - } + fs.chmodSync(path.join(currentDir, 'bw'), currentMode != null ? currentMode : '764'); res.title = 'Updated self to ' + tagName + '.'; if (responseJson.body != null && responseJson.body !== '') { res.message = responseJson.body; } return Response.success(res); } catch { - return Response.error('Error extracting update to ' + __dirname); + return Response.error('Error extracting update to ' + currentDir); } } else { return Response.error('Error downloading update: ' + zipResponse.status); @@ -96,9 +93,16 @@ export class UpdateCommand { if (responseJson.body != null && responseJson.body !== '') { res.message = responseJson.body + '\n\n'; } - res.message += 'You can download this update at: ' + downloadUrl + '\n' + - 'or run `bw update --self`\n\n' + - 'If you installed this CLI through a package manager ' + + + res.message += 'You can download this update at ' + downloadUrl; + + if ((cmd.self || false) && process.platform === 'win32') { + res.message += '\n`--self` updates are not available on Windows.'; + } else if (process.platform !== 'win32') { + res.message += '\nor just run `bw update --self`'; + } + + res.message += '\n\nIf you installed this CLI through a package manager ' + 'you should probably update using its update command instead.'; return Response.success(res); } else { diff --git a/src/program.ts b/src/program.ts index f767adc4d5..8c344723e6 100644 --- a/src/program.ts +++ b/src/program.ts @@ -474,6 +474,8 @@ export class Program { writeLn(''); writeLn(' Use the `--raw` option to return only the download URL for the update.'); writeLn(''); + writeLn(' `--self` updates are not available on Windows.'); + writeLn(''); writeLn(' Examples:'); writeLn(''); writeLn(' bw update');