npm: upgrade to v1.4.14
[platform/upstream/nodejs.git] / deps / npm / node_modules / npm-registry-client / lib / get.js
index bb6d525..9aab7d7 100644 (file)
@@ -10,7 +10,6 @@ function get (uri, timeout, nofollow, staleOk, cb) {
   if (typeof cb !== "function") cb = staleOk, staleOk = false
   if (typeof cb !== "function") cb = nofollow, nofollow = false
   if (typeof cb !== "function") cb = timeout, timeout = -1
-  if (typeof cb !== "function") cb = version, version = null
 
   timeout = Math.min(timeout, this.conf.get('cache-max') || 0)
   timeout = Math.max(timeout, this.conf.get('cache-min') || -Infinity)
@@ -22,18 +21,15 @@ function get (uri, timeout, nofollow, staleOk, cb) {
     && process.env.COMP_POINT !== undefined
     ) timeout = Math.max(timeout, 60000)
 
+  var cache = this.cacheFile(this.registry + uri) + "/.cache.json"
+
   // /-/all is special.
   // It uses timestamp-based caching and partial updates,
   // because it is a monster.
   if (uri === "/-/all") {
-    return requestAll.call(this, cb)
+    return requestAll.call(this, cache, cb)
   }
 
-  var cacheUri = uri
-  // on windows ":" is not an allowed character in a foldername
-  cacheUri = cacheUri.replace(/:/g, '_').replace(/\?write=true$/, '')
-  var cache = path.join(this.conf.get('cache'), cacheUri, ".cache.json")
-
   // If the GET is part of a write operation (PUT or DELETE), then
   // skip past the cache entirely, but still save the results.
   if (uri.match(/\?write=true$/))
@@ -50,27 +46,25 @@ function get (uri, timeout, nofollow, staleOk, cb) {
   }.bind(this))
 }
 
-function requestAll (cb) {
-  var cache = path.join(this.conf.get('cache'), "/-/all", ".cache.json")
-
-  mkdir(path.join(this.conf.get('cache'), "-", "all"), function (er) {
+function requestAll (cache, cb) {
+  mkdir(path.dirname(cache), function (er) {
     fs.readFile(cache, function (er, data) {
-      if (er) return requestAll_.call(this, 0, {}, cb)
+      if (er) return requestAll_.call(this, 0, {}, cache, cb)
       try {
         data = JSON.parse(data)
       } catch (ex) {
         fs.writeFile(cache, "{}", function (er) {
           if (er) return cb(new Error("Broken cache."))
-          return requestAll_.call(this, 0, {}, cb)
+          return requestAll_.call(this, 0, {}, cache, cb)
         }.bind(this))
       }
       var t = +data._updated || 0
-      requestAll_.call(this, t, data, cb)
+      requestAll_.call(this, t, data, cache, cb)
     }.bind(this))
   }.bind(this))
 }
 
-function requestAll_ (c, data, cb) {
+function requestAll_ (c, data, cache, cb) {
   // use the cache and update in the background if it's not too old
   if (Date.now() - c < 60000) {
     cb(null, data)
@@ -84,7 +78,6 @@ function requestAll_ (c, data, cb) {
     uri = "/-/all"
   }
 
-  var cache = path.join(this.conf.get('cache'), "-/all", ".cache.json")
   this.request('GET', uri, function (er, updates, _, res) {
     if (er) return cb(er, data)
     var headers = res.headers