From a9e03ce6d28dcd581dc1e659129f878afff787f0 Mon Sep 17 00:00:00 2001 From: MariaDima Date: Fri, 16 Jun 2017 10:40:04 +0200 Subject: [PATCH] fix(electron-updater): No notification in case of an error during signature verification Close #1680, Close #1681 --- packages/electron-updater/src/NsisUpdater.ts | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/electron-updater/src/NsisUpdater.ts b/packages/electron-updater/src/NsisUpdater.ts index 2a5ee34e3c5..cf90a29bc07 100644 --- a/packages/electron-updater/src/NsisUpdater.ts +++ b/packages/electron-updater/src/NsisUpdater.ts @@ -36,15 +36,22 @@ export class NsisUpdater extends AppUpdater { const tempDir = await mkdtemp(`${path.join(tmpdir(), "up")}-`) const tempFile = path.join(tempDir, fileInfo.name) - try { - await this.httpExecutor.download(fileInfo.url, tempFile, downloadOptions) - } - catch (e) { + + let removeTempDirIfAny = async () => { try { await remove(tempDir) } catch (ignored) { } + } + + let signatureVerificationStatus + try { + await this.httpExecutor.download(fileInfo.url, tempFile, downloadOptions) + signatureVerificationStatus = await this.verifySignature(tempFile) + } + catch (e) { + await removeTempDirIfAny() if (e instanceof CancellationError) { this.emit("update-cancelled", this.versionInfo) @@ -53,15 +60,10 @@ export class NsisUpdater extends AppUpdater { throw e } - const signatureVerificationStatus = await this.verifySignature(tempFile) if (signatureVerificationStatus != null) { - try { - await remove(tempDir) - } - finally { - // noinspection ThrowInsideFinallyBlockJS - throw new Error(`New version ${this.versionInfo!.version} is not signed by the application owner: ${signatureVerificationStatus}`) - } + await removeTempDirIfAny() + // noinspection ThrowInsideFinallyBlockJS + throw new Error(`New version ${this.versionInfo!.version} is not signed by the application owner: ${signatureVerificationStatus}`) } this._logger.info(`New version ${this.versionInfo!.version} has been downloaded to ${tempFile}`)