summaryrefslogtreecommitdiff
path: root/deps/npm/lib/cache/add-remote-git.js
diff options
context:
space:
mode:
authorTimothy J Fontaine <tjfontaine@gmail.com>2014-09-24 14:41:07 -0700
committerTimothy J Fontaine <tjfontaine@gmail.com>2014-09-24 17:15:10 -0700
commit9fad8958df671c0e894506ef59b4c781c3dfb349 (patch)
tree4db7643b40c4ffd726fb27fb4aa276d420b3bfd8 /deps/npm/lib/cache/add-remote-git.js
parentb26dd4e5ab9192bad72b9dc61fa4ad2d8f215da2 (diff)
downloadnode-9fad8958df671c0e894506ef59b4c781c3dfb349.tar.gz
deps: upgrade npm to 2.0.0
Diffstat (limited to 'deps/npm/lib/cache/add-remote-git.js')
-rw-r--r--deps/npm/lib/cache/add-remote-git.js65
1 files changed, 55 insertions, 10 deletions
diff --git a/deps/npm/lib/cache/add-remote-git.js b/deps/npm/lib/cache/add-remote-git.js
index 7743aa4a4..304d2f3f0 100644
--- a/deps/npm/lib/cache/add-remote-git.js
+++ b/deps/npm/lib/cache/add-remote-git.js
@@ -8,9 +8,7 @@ var mkdir = require("mkdirp")
, url = require("url")
, chownr = require("chownr")
, zlib = require("zlib")
- , which = require("which")
, crypto = require("crypto")
- , chmodr = require("chmodr")
, npm = require("../npm.js")
, rm = require("../utils/gently-rm.js")
, inflight = require("inflight")
@@ -28,9 +26,8 @@ var mkdir = require("mkdirp")
// 5. git archive /tmp/random.tgz
// 6. addLocalTarball(/tmp/random.tgz) <gitref> --format=tar --prefix=package/
// silent flag is used if this should error quietly
-module.exports = function addRemoteGit (u, parsed, silent, cb_) {
+module.exports = function addRemoteGit (u, silent, cb_) {
assert(typeof u === "string", "must have git URL")
- assert(typeof parsed === "object", "must have parsed query")
assert(typeof cb_ === "function", "must have callback")
function cb (er, data) {
@@ -41,6 +38,10 @@ module.exports = function addRemoteGit (u, parsed, silent, cb_) {
if (!cb_) return
+ log.verbose("addRemoteGit", "u=%j silent=%j", u, silent)
+ var parsed = url.parse(u, true)
+ log.silly("addRemoteGit", "parsed", parsed)
+
// git is so tricky!
// if the path is like ssh://foo:22/some/path then it works, but
// it needs the ssh://
@@ -62,16 +63,16 @@ module.exports = function addRemoteGit (u, parsed, silent, cb_) {
var co = parsed.hash && parsed.hash.substr(1) || "master"
var v = crypto.createHash("sha1").update(u).digest("hex").slice(0, 8)
- v = u.replace(/[^a-zA-Z0-9]+/g, '-') + '-' + v
+ v = u.replace(/[^a-zA-Z0-9]+/g, "-")+"-"+v
log.verbose("addRemoteGit", [u, co])
var p = path.join(npm.config.get("cache"), "_git-remotes", v)
checkGitDir(p, u, co, origUrl, silent, function(er, data) {
- chmodr(p, npm.modes.file, function(erChmod) {
+ addModeRecursive(p, npm.modes.file, function(erAddMode) {
if (er) return cb(er, data)
- return cb(erChmod, data)
+ return cb(erAddMode, data)
})
})
})
@@ -181,16 +182,20 @@ function archiveGitRemote (p, u, co, origUrl, cb) {
parsed.hash = stdout
resolved = url.format(parsed)
+ if (parsed.protocol !== "git:") {
+ resolved = "git+" + resolved
+ }
+
// https://github.com/npm/npm/issues/3224
// node incorrectly sticks a / at the start of the path
// We know that the host won't change, so split and detect this
var spo = origUrl.split(parsed.host)
var spr = resolved.split(parsed.host)
- if (spo[1].charAt(0) === ':' && spr[1].charAt(0) === '/')
+ if (spo[1].charAt(0) === ":" && spr[1].charAt(0) === "/")
spr[1] = spr[1].slice(1)
resolved = spr.join(parsed.host)
- log.verbose('resolved git url', resolved)
+ log.verbose("resolved git url", resolved)
next()
})
}
@@ -226,8 +231,48 @@ function gitEnv () {
if (gitEnv_) return gitEnv_
gitEnv_ = {}
for (var k in process.env) {
- if (!~['GIT_PROXY_COMMAND','GIT_SSH','GIT_SSL_NO_VERIFY'].indexOf(k) && k.match(/^GIT/)) continue
+ if (!~["GIT_PROXY_COMMAND","GIT_SSH","GIT_SSL_NO_VERIFY"].indexOf(k) && k.match(/^GIT/)) continue
gitEnv_[k] = process.env[k]
}
return gitEnv_
}
+
+// similar to chmodr except it add permissions rather than overwriting them
+// adapted from https://github.com/isaacs/chmodr/blob/master/chmodr.js
+function addModeRecursive(p, mode, cb) {
+ fs.readdir(p, function (er, children) {
+ // Any error other than ENOTDIR means it's not readable, or doesn't exist.
+ // Give up.
+ if (er && er.code !== "ENOTDIR") return cb(er)
+ if (er || !children.length) return addMode(p, mode, cb)
+
+ var len = children.length
+ var errState = null
+ children.forEach(function (child) {
+ addModeRecursive(path.resolve(p, child), mode, then)
+ })
+
+ function then (er) {
+ if (errState) return undefined
+ if (er) return cb(errState = er)
+ if (--len === 0) return addMode(p, dirMode(mode), cb)
+ }
+ })
+}
+
+function addMode(p, mode, cb) {
+ fs.stat(p, function (er, stats) {
+ if (er) return cb(er)
+ mode = stats.mode | mode
+ fs.chmod(p, mode, cb)
+ })
+}
+
+// taken from https://github.com/isaacs/chmodr/blob/master/chmodr.js
+function dirMode(mode) {
+ if (mode & parseInt("0400", 8)) mode |= parseInt("0100", 8)
+ if (mode & parseInt( "040", 8)) mode |= parseInt( "010", 8)
+ if (mode & parseInt( "04", 8)) mode |= parseInt( "01", 8)
+ return mode
+}
+