Skip to content

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 sass#1882
Fixes sass#1888
  • Loading branch information
xzyfer committed Feb 22, 2017
1 parent eb7f013 commit 5003a64
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 5003a64

Please # to comment.