From 963f1a11eb8994111b860de4c769725f9ff0ec00 Mon Sep 17 00:00:00 2001 From: Jonas Hermsmeier Date: Fri, 20 Apr 2018 01:01:24 +0200 Subject: [PATCH] fix(gui): Fix zero-zero devices when verify is disabled This fixes a state where the success screen would display zero succeeded and zero failed devices if verification was turned off. This could occur due to the "done" event being emitted before the next progress event could set the relevant data. Change-Type: patch --- lib/gui/app/modules/image-writer.js | 13 ++--------- .../pages/finish/templates/success.tpl.html | 2 +- lib/sdk/writer/index.js | 23 ++++++++++++++----- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/gui/app/modules/image-writer.js b/lib/gui/app/modules/image-writer.js index ec38ebbf..026012b8 100644 --- a/lib/gui/app/modules/image-writer.js +++ b/lib/gui/app/modules/image-writer.js @@ -126,12 +126,7 @@ exports.performWrite = (image, drives, onProgress) => { console.log(message) }) - const flashResults = { - devices: { - succeeded: 0, - failed: 0 - } - } + const flashResults = {} ipc.server.on('fail', (error) => { console.log('Fail:', error) @@ -144,11 +139,7 @@ exports.performWrite = (image, drives, onProgress) => { _.merge(flashResults, event) }) - ipc.server.on('state', (progress) => { - flashResults.devices.succeeded = progress.succeeded - flashResults.devices.failed = progress.failed - onProgress(progress) - }) + ipc.server.on('state', onProgress) ipc.server.on('ready', (data, socket) => { ipc.server.emit(socket, 'write', { diff --git a/lib/gui/app/pages/finish/templates/success.tpl.html b/lib/gui/app/pages/finish/templates/success.tpl.html index 0a47aff7..87eba293 100644 --- a/lib/gui/app/pages/finish/templates/success.tpl.html +++ b/lib/gui/app/pages/finish/templates/success.tpl.html @@ -6,7 +6,7 @@

Flash Complete!

+ ng-repeat="(type, quantity) in finish.flash.getFlashResults().results.devices"> {{ quantity }} {{ finish.progressMessage[type](quantity) }} diff --git a/lib/sdk/writer/index.js b/lib/sdk/writer/index.js index 14a0c184..c30a6783 100644 --- a/lib/sdk/writer/index.js +++ b/lib/sdk/writer/index.js @@ -350,6 +350,7 @@ class ImageWriter extends EventEmitter { // Generate preparation tasks for all destinations const tasks = destinations.map((destination) => { + destination.verified = !this.verifyChecksums this.destinations.set(destination.device.device, destination) return (next) => { runSeries([ @@ -632,17 +633,27 @@ class ImageWriter extends EventEmitter { */ _finish () { this._cleanup(() => { + const failures = [] + let succeeded = 0 + let failed = 0 + this.finished = true + + this.destinations.forEach((dest) => { + succeeded += dest.finished && dest.verified && !dest.error ? 1 : 0 + failed += dest.error ? 1 : 0 + if (dest.error) { + dest.error.device = dest.device.device + failures.push(dest.error) + } + }) + this.emit('finish', { + devices: { succeeded, failed }, bytesRead: this.bytesRead, bytesWritten: this.bytesWritten, checksum: this.checksum, - errors: Array.from(this.destinations).filter(([ device, dest ]) => { - return dest.error - }).map(([ device, dest ]) => { - dest.error.device = device - return dest.error - }) + errors: failures }) }) }