Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use getCacheStat before lock, fixes joyent/node#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.
  • Loading branch information...
commit 9604ee75a7a65284240b018a8f5413564c443e4a 1 parent 365cb71
@francoisfrisch authored
Showing with 10 additions and 16 deletions.
  1. +10 −16 lib/cache.js
View
26 lib/cache.js
@@ -1195,27 +1195,21 @@ 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()
+ var opts = { stale: npm.config.get("cache-lock-stale")
+ , retries: npm.config.get("cache-lock-retries")
+ , wait: npm.config.get("cache-lock-wait") }
+ var lf = lockFileName(u)
+ log.verbose("lock", u, lf)
+ lockFile.lock(lf, opts, function(er) {
+ if (!er) myLocks[lf] = true
+ cb(er)
+ })
})
- 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") }
- var lf = lockFileName(u)
- log.verbose("lock", u, lf)
- lockFile.lock(lf, opts, function(er) {
- if (!er) myLocks[lf] = true
- cb(er)
- })
- }
}
function unlock (u, cb) {
Please sign in to comment.
Something went wrong with that request. Please try again.