Permalink
Browse files

Verify ownership of git cloned/fetched files

In the case when people use `sudo npm install -g` some of the cloned git dependencies go to the npm cache. In this case when npm executes git clone or fetch, git sets ownership to root. This cases troubles when you try to do later `npm install` for dependencies which already under npm_cache/_git-remotes/ and has root ownership.

This change can cause performance degradation when you have a lot of git dependencies, because each time when you ask for git dependency - it will verify ownership first for all files under git folder. Better option will be to change ownership only for new fetched/cloned files.
  • Loading branch information...
1 parent 8e4fa63 commit a132690a2876cda5dcd1e4ca751f21dfcb11cb9e @outcoldman outcoldman committed with domenic Jan 10, 2014
Showing with 17 additions and 1 deletion.
  1. +17 −1 lib/cache.js
View
@@ -508,9 +508,25 @@ function archiveGitRemote (p, u, co, origUrl, cb) {
}
log.verbose("git fetch -a origin ("+u+")", stdout)
tmp = path.join(npm.tmp, Date.now()+"-"+Math.random(), "tmp.tgz")
- resolveHead()
+ verifyOwnership()
})
+ function verifyOwnership() {
+ getCacheStat(function(er, cs) {
+ if (er) {
+ log.error("Could not get cache stat")
+ return cb(er)
+ }
+ chownr(p, cs.uid, cs.gid, function(er) {
+ if (er) {
+ log.error("Failed to change folder ownership under npm cache for %s", p)
+ return cb(er)
+ }
+ resolveHead()
+ })
+ })
+ }
+
function resolveHead () {
exec(git, resolve, {cwd: p, env: env}, function (er, stdout, stderr) {
stdout = (stdout + "\n" + stderr).trim()

0 comments on commit a132690

Please sign in to comment.