From 36664fb251e9ca3d111cdabeeed2a1c23b43028e Mon Sep 17 00:00:00 2001 From: Jonas Hermsmeier Date: Mon, 24 Jul 2017 21:54:02 +0200 Subject: [PATCH] fix(writer): Use final size if it's not an estimation (#1587) This avoids running into the "flashstate percentage above 100%" error again. Change-Type: patch Changelog-Entry: Prevent "percentage above 100%" errors on DMG images. --- lib/image-stream/handlers.js | 4 +++- tests/image-stream/dmg.spec.js | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/image-stream/handlers.js b/lib/image-stream/handlers.js index 62069f89..ee5f838c 100644 --- a/lib/image-stream/handlers.js +++ b/lib/image-stream/handlers.js @@ -157,7 +157,9 @@ module.exports = { extension: fileExtensions.getLastFileExtension(imagePath), stream: udif.createReadStream(imagePath), size: { - original: options.size, + // FIXME(jhermsmeier): Originally `options.size`, + // See discussion in https://github.com/resin-io/etcher/pull/1587 + original: size || options.size, final: { estimation: false, value: size diff --git a/tests/image-stream/dmg.spec.js b/tests/image-stream/dmg.spec.js index 1b52283f..a36e382b 100644 --- a/tests/image-stream/dmg.spec.js +++ b/tests/image-stream/dmg.spec.js @@ -81,14 +81,13 @@ describe('ImageStream: DMG', function() { it('should return the correct metadata', function() { const image = path.join(DMG_PATH, 'etcher-test-zlib.dmg'); const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size; - const compressedSize = fs.statSync(image).size; return imageStream.getImageMetadata(image).then((metadata) => { m.chai.expect(metadata).to.deep.equal({ path: image, extension: 'dmg', size: { - original: compressedSize, + original: uncompressedSize, final: { estimation: false, value: uncompressedSize @@ -122,14 +121,13 @@ describe('ImageStream: DMG', function() { it('should return the correct metadata', function() { const image = path.join(DMG_PATH, 'etcher-test-raw.dmg'); const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size; - const compressedSize = fs.statSync(image).size; return imageStream.getImageMetadata(image).then((metadata) => { m.chai.expect(metadata).to.deep.equal({ path: image, extension: 'dmg', size: { - original: compressedSize, + original: uncompressedSize, final: { estimation: false, value: uncompressedSize