From 389835029f393bb8fdc85d26786c71bcca2845f7 Mon Sep 17 00:00:00 2001 From: xzyfer Date: Wed, 22 Feb 2017 21:27:07 +1100 Subject: [PATCH] Install script should not write partially downloaded binaries Currently the binary download is streamed to disk once a 200 response has been recieved. When an error occurs during the download a partially downloaded binary is left on disk. Subsequent installs see the binary and bail out of re-downloading it. Worse yet those subsequent installs move the binary into the global cache so even removing node_modules will not remove the broken binary. With this patch the binary is only flushed to disk once it has been fully downloaded. Fixes #1882 Fixes #1888 --- scripts/install.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/install.js b/scripts/install.js index 099b2c2b8..35bcf14fe 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -58,6 +58,11 @@ function download(url, dest, cb) { reportError(['HTTP error', response.statusCode, response.statusMessage].join(' ')); } else { console.log('Download complete'); + + if (successful(response)) { + response.pipe(fs.createWriteStream(dest)); + } + cb(); } }) @@ -65,10 +70,6 @@ function download(url, dest, cb) { var length = parseInt(response.headers['content-length'], 10); var progress = log.newItem('', length); - if (successful(response)) { - response.pipe(fs.createWriteStream(dest)); - } - // The `progress` is true by default. However if it has not // been explicitly set it's `undefined` which is considered // as far as npm is concerned.