Permalink
Browse files

use getCacheStat before lock, fixes nodejs/node-v0.x-archive#3821

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...
1 parent 365cb71 commit dd9ddb58ed5278607f47ae9b46ea93106135131f @francoisfrisch committed with Jun 1, 2013
Showing with 2 additions and 8 deletions.
  1. +2 −8 lib/cache.js
View
@@ -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") }
@@ -1215,7 +1209,7 @@ function lock (u, cb) {
if (!er) myLocks[lf] = true
cb(er)
})
- }
+ })
}
function unlock (u, cb) {

0 comments on commit dd9ddb5

Please sign in to comment.