Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

fix pipe not emit finish on tarball in 0.10.30 #5958

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 23 additions & 31 deletions lib/cache/add-remote-tarball.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,33 @@ function fetchAndShaCheck (u, tmp, shasum, cb) {
return cb(er, response)
}

// mkdir takes a little while, so don't drop chunks!
response.pause()

mkdir(path.dirname(tmp), function (er) {
if (er) return cb(er)
var tarball = createWriteStream(tmp, { mode : npm.modes.file })
tarball.on("error", function (er) {
cb(er)
tarball.destroy()
})

var tarball = createWriteStream(tmp, { mode : npm.modes.file })
tarball.on("error", function (er) {
cb(er)
tarball.destroy()
})
tarball.on("finish", function () {
if (!shasum) {
// Well, we weren't given a shasum, so at least sha what we have
// in case we want to compare it to something else later
return sha.get(tmp, function (er, shasum) {
log.silly("fetchAndShaCheck", "shasum", shasum)
cb(er, response, shasum)
})
}

tarball.on("finish", function () {
if (!shasum) {
// Well, we weren't given a shasum, so at least sha what we have
// in case we want to compare it to something else later
return sha.get(tmp, function (er, shasum) {
log.silly("fetchAndShaCheck", "shasum", shasum)
cb(er, response, shasum)
})
// validate that the url we just downloaded matches the expected shasum.
log.silly("fetchAndShaCheck", "shasum", shasum)
sha.check(tmp, shasum, function (er) {
if (er && er.message) {
// add original filename for better debuggability
er.message = er.message + "\n" + "From: " + u
}

// validate that the url we just downloaded matches the expected shasum.
log.silly("fetchAndShaCheck", "shasum", shasum)
sha.check(tmp, shasum, function (er) {
if (er && er.message) {
// add original filename for better debuggability
er.message = er.message + "\n" + "From: " + u
}
return cb(er, response, shasum)
})
return cb(er, response, shasum)
})

response.pipe(tarball)
response.resume()
})

response.pipe(tarball)
})
}