diff options
author | isaacs <i@izs.me> | 2011-10-21 03:24:29 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-10-21 03:24:29 +0400 |
commit | 19bbc786ec80ba6fd77e92aea7cb1b75032ce81f (patch) | |
tree | 5a539ef88d6d04f04452643bbb82b228af3fbf4c /lib | |
parent | 08287b0d2b038d2b71f93719faf4a363fcac3709 (diff) |
Close #1509 Don't chmod the npm.prefix folder, just ensure it's there.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/npm.js | 2 | ||||
-rw-r--r-- | lib/utils/mkdir-p.js | 29 |
2 files changed, 20 insertions, 11 deletions
diff --git a/lib/npm.js b/lib/npm.js index d40b85ca4..31e1815e8 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -317,7 +317,7 @@ function loadPrefix (npm, conf, cb) { , enumerable : true }) // the prefix MUST exist, or else nothing works. - mkdir(p, cb) + mkdir(p, null, null, null, true, cb) }) } diff --git a/lib/utils/mkdir-p.js b/lib/utils/mkdir-p.js index 645e45d02..4f8de784d 100644 --- a/lib/utils/mkdir-p.js +++ b/lib/utils/mkdir-p.js @@ -11,7 +11,8 @@ var log = require("./log.js") , mkdirCache = {} module.exports = mkdir -function mkdir (ensure, mode, uid, gid, cb_) { +function mkdir (ensure, mode, uid, gid, noChmod, cb_) { + if (typeof cb_ !== "function") cb_ = noChmod, noChmod = null if (typeof cb_ !== "function") cb_ = gid, gid = null if (typeof cb_ !== "function") cb_ = uid, uid = null if (typeof cb_ !== "function") cb_ = mode, mode = npm.modes.exec @@ -46,36 +47,44 @@ function mkdir (ensure, mode, uid, gid, cb_) { } if (uid === null && gid === null) { - return mkdir_(ensure, mode, uid, gid, cb) + return mkdir_(ensure, mode, uid, gid, noChmod, cb) } uidNumber(uid, gid, function (er, uid, gid) { if (er) return cb(er) - mkdir_(ensure, mode, uid, gid, cb) + mkdir_(ensure, mode, uid, gid, noChmod, cb) }) } -function mkdir_ (ensure, mode, uid, gid, cb) { +function mkdir_ (ensure, mode, uid, gid, noChmod, cb) { // if it's already a dir, then just check the bits and owner. fs.stat(ensure, function (er, s) { if (s && s.isDirectory()) { // check mode, uid, and gid. - if ((s.mode & mode) === mode + if ((noChmod || (s.mode & mode) === mode) && (typeof uid !== "number" || s.uid === uid) && (typeof gid !== "number" || s.gid === gid)) return cb() - return done(ensure, mode, uid, gid, cb) + return done(ensure, mode, uid, gid, noChmod, cb) } - return walkDirs(ensure, mode, uid, gid, cb) + return walkDirs(ensure, mode, uid, gid, noChmod, cb) }) } -function done (ensure, mode, uid, gid, cb) { +function done (ensure, mode, uid, gid, noChmod, cb) { // now the directory has been created. // chown it to the desired uid/gid // Don't chown the npm.root dir, though, in case we're // in unsafe-perm mode. log.verbose("done: "+ensure+" "+mode.toString(8), "mkdir") - fs.chmod(ensure, mode, function (er) { + + // only chmod if noChmod isn't set. + var d = done_(ensure, mode, uid, gid, noChmod, cb) + if (noChmod) return d() + fs.chmod(ensure, mode, d) +} + +function done_ (ensure, mode, uid, gid, noChmod, cb) { + return function (er) { if (er || ensure === npm.dir || typeof uid !== "number" @@ -84,7 +93,7 @@ function done (ensure, mode, uid, gid, cb) { uid = Math.floor(uid) gid = Math.floor(gid) fs.chown(ensure, uid, gid, cb) - }) + } } var pathSplit = process.platform === "win32" ? /\/|\\/ : "/" |