Skip to content

Commit

Permalink
use getCacheStat before lock, fixes nodejs/node-v0.x-archive#3821
Browse files Browse the repository at this point in the history
Previous code did not handle the cache dir's permissions consistently.
If the first lock was done as sudo, the cache directory was not user
writable.
Removed the now unnecessary guard and collapsed the then function.
  • Loading branch information
francoisfrisch committed Jun 3, 2013
1 parent 365cb71 commit dd9ddb5
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -1195,17 +1195,11 @@ function lockFileName (u) {
return path.resolve(npm.config.get("cache"), h + "-" + c + ".lock")
}

var madeCache = false
var myLocks = {}
function lock (u, cb) {
// the cache dir needs to exist already for this.
if (madeCache) then()
else mkdir(npm.config.get("cache"), function (er) {
getCacheStat(function (er, cs) {
if (er) return cb(er)
madeCache = true
then()
})
function then () {
var opts = { stale: npm.config.get("cache-lock-stale")
, retries: npm.config.get("cache-lock-retries")
, wait: npm.config.get("cache-lock-wait") }
Expand All @@ -1215,7 +1209,7 @@ function lock (u, cb) {
if (!er) myLocks[lf] = true
cb(er)
})
}
})
}

function unlock (u, cb) {
Expand Down

0 comments on commit dd9ddb5

Please sign in to comment.