Skip to content
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 dcef57f commit 7ac339c420674ef870e13448ab0e3aa13cff8552 @francoisfrisch francoisfrisch committed with domenic May 31, 2013
Showing with 2 additions and 8 deletions.
  1. +2 −8 lib/cache.js
View
10 lib/cache.js
@@ -1203,17 +1203,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") }
@@ -1223,7 +1217,7 @@ function lock (u, cb) {
if (!er) myLocks[lf] = true
cb(er)
})
- }
+ })
}
function unlock (u, cb) {

0 comments on commit 7ac339c

Please sign in to comment.
Something went wrong with that request. Please try again.