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

Commit

Permalink
remove repeating mkdir in cache/add-remote-tarball.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored and othiym23 committed Aug 21, 2014
1 parent ccc1e2e commit 16bead7
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions lib/cache/add-remote-tarball.js
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)
})
}

0 comments on commit 16bead7

Please sign in to comment.