Skip to content

Commit

Permalink
fix(electron-updater): No notification in case of an error during sig…
Browse files Browse the repository at this point in the history
…nature verification

Close #1680, Close #1681
  • Loading branch information
MariaDima authored and develar committed Jun 16, 2017
1 parent a8c9ffd commit a9e03ce
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/electron-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}`)
Expand Down

0 comments on commit a9e03ce

Please sign in to comment.