Commit 38983502 by xzyfer Committed by Michael Mifsud

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
parent 3331891a
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment