Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cache.js')
-rw-r--r--lib/cache.js42
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/cache.js b/lib/cache.js
index a57ff308f..b62e82dd1 100644
--- a/lib/cache.js
+++ b/lib/cache.js
@@ -31,7 +31,7 @@ exports.read = read
exports.clean = clean
exports.unpack = unpack
-var mkdir = require("./utils/mkdir-p.js")
+var mkdir = require("mkdirp")
, exec = require("./utils/exec.js")
, fetch = require("./utils/fetch.js")
, npm = require("./npm.js")
@@ -49,6 +49,7 @@ var mkdir = require("./utils/mkdir-p.js")
, tar = require("./utils/tar.js")
, fileCompletion = require("./utils/completion/file-completion.js")
, url = require("url")
+ , chownr = require("chownr")
cache.usage = "npm cache add <tarball file>"
+ "\nnpm cache add <folder>"
@@ -633,7 +634,7 @@ function getCacheStat (cb) {
}
function makeCacheDir (cb) {
- if (!process.getuid) return mkdir(npm.cache, npm.modes.exec, cb)
+ if (!process.getuid) return mkdir(npm.cache, cb)
var uid = +process.getuid()
, gid = +process.getgid()
@@ -644,18 +645,28 @@ function makeCacheDir (cb) {
}
if (uid !== 0 || !process.env.HOME) {
cacheStat = {uid: uid, gid: gid}
- return mkdir(npm.cache, npm.modes.exec, uid, gid, function (er) {
- return cb(er, cacheStat)
- })
+ return mkdir(npm.cache, afterMkdir)
}
+
fs.stat(process.env.HOME, function (er, st) {
if (er) return log.er(cb, "homeless?")(er)
cacheStat = st
log.silly([st.uid, st.gid], "uid, gid for cache dir")
- return mkdir(npm.cache, npm.modes.exec, st.uid, st.gid, function (er) {
+ return mkdir(npm.cache, afterMkdir)
+ })
+
+ function afterMkdir (er, made) {
+ if (er || !cacheStat || isNaN(cacheStat.uid) || isNaN(cacheStat.gid)) {
+ return cb(er, cacheStat)
+ }
+
+ if (!made) return cb(er, cacheStat)
+
+ // ensure that the ownership is correct.
+ chownr(made, cacheStat.uid, cacheStat.gid, function (er) {
return cb(er, cacheStat)
})
- })
+ }
}
@@ -733,9 +744,20 @@ function addLocalDirectory (p, name, cb) {
, tgz = placeDirect ? placed : tmptgz
, doFancyCrap = p.indexOf(npm.tmp) !== 0
&& p.indexOf(npm.cache) !== 0
- tar.pack(tgz, p, data, doFancyCrap, function (er) {
- if (er) return log.er(cb,"couldn't pack "+p+ " to "+tgz)(er)
- addLocalTarball(tgz, name, cb)
+ getCacheStat(function (er, cs) {
+ mkdir(path.dirname(tgz), function (er, made) {
+ if (er) return cb(er)
+ tar.pack(tgz, p, data, doFancyCrap, function (er) {
+ if (er) return log.er(cb,"couldn't pack "+p+ " to "+tgz)(er)
+
+ if (er || !cs || isNaN(cs.uid) || isNaN(cs.gid)) return cb()
+
+ chownr(made || tgz, cs.uid, cs.gid, function (er) {
+ if (er) return cb(er)
+ addLocalTarball(tgz, name, cb)
+ })
+ })
+ })
})
})
}