Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Install script should not write partially downloaded binaries
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xzyfer committed Mar 10, 2018
1 parent 3331891 commit 3898350
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ 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();
}
})
.on('response', function(response) {
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.
Expand Down

0 comments on commit 3898350

Please sign in to comment.