Skip to content

Commit 296f407

Browse files
committed
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 sass#1882 Fixes sass#1888
1 parent b926705 commit 296f407

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/install.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,18 @@ function download(url, dest, cb) {
5858
reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
5959
} else {
6060
console.log('Download complete');
61+
62+
if (successful(response)) {
63+
response.pipe(fs.createWriteStream(dest));
64+
}
65+
6166
cb();
6267
}
6368
})
6469
.on('response', function(response) {
6570
var length = parseInt(response.headers['content-length'], 10);
6671
var progress = log.newItem('', length);
6772

68-
if (successful(response)) {
69-
response.pipe(fs.createWriteStream(dest));
70-
}
71-
7273
// The `progress` is true by default. However if it has not
7374
// been explicitly set it's `undefined` which is considered
7475
// as far as npm is concerned.

0 commit comments

Comments
 (0)