diff options
author | isaacs <i@izs.me> | 2011-06-16 04:03:58 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-06-16 04:03:58 +0400 |
commit | f5fd16329e685fa63d00c365ee128d565c602948 (patch) | |
tree | b447f5f886f2b9ddaeaaa2212d094b7f0fbc3f33 | |
parent | 06dd026d04768edd7adf2aa37cf9a8d9e8c335be (diff) |
Properly handle 304 responses, and duplicate less
-rw-r--r-- | lib/cache.js | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/cache.js b/lib/cache.js index 23b2e295e..a9311fd9e 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -98,7 +98,7 @@ function cache (args, cb) { var cacheSeen = {} function read (name, ver, forceBypass, cb) { if (typeof cb !== "function") cb = forceBypass, forceBypass = true - var jsonFile = path.join(npm.cache, name, ver, "package.json") + var jsonFile = path.join(npm.cache, name, ver, "package", "package.json") function c (er, data) { if (!er) cacheSeen[data._id] = data if (data) deprCheck(data) @@ -345,7 +345,12 @@ function addNameVersion (name, ver, cb) { // we got cached data, so let's see if we have a tarball. fs.stat(path.join(npm.cache, name, ver, "package.tgz"), function (er, s) { - if (!er) return cb(null, data) + if (!er) readJson( path.join( npm.cache, name, ver + , "package", "package.json" ) + , function (er, data) { + if (er) return fetchit() + return cb(null, data) + }) else return fetchit() }) @@ -479,7 +484,6 @@ function addPlacedTarball_ (p, name, uid, gid, cb) { // and fire cb with the json data. var target = path.dirname(p) , folder = path.join(target, "package") - , json = path.join(target, "package.json") rm(folder, function (er) { if (er) return log.er(cb, "Could not remove "+folder)(er) @@ -494,16 +498,13 @@ function addPlacedTarball_ (p, name, uid, gid, cb) { data.dist = data.dist || {} if (shasum) data.dist.shasum = shasum deprCheck(data) - fs.writeFile(json, JSON.stringify(data,null,2), function (er) { - if (er) return log.er(cb, "Could not write to "+json)(er) - asyncMap([json, p], function (f, cb) { - log.verbose(FMODE.toString(8), "chmod "+f) - fs.chmod(f, FMODE, cb) - }, function (f, cb) { - fs.chown(f, uid, gid, cb) - }, function (er) { - cb(er, data) - }) + asyncMap([p], function (f, cb) { + log.verbose(FMODE.toString(8), "chmod "+f) + fs.chmod(f, FMODE, cb) + }, function (f, cb) { + fs.chown(f, uid, gid, cb) + }, function (er) { + cb(er, data) }) }) }) |