diff --git a/lib/utils/correct-mkdir.js b/lib/utils/correct-mkdir.js index 83c94c784b264..650c56fb17deb 100644 --- a/lib/utils/correct-mkdir.js +++ b/lib/utils/correct-mkdir.js @@ -34,15 +34,15 @@ module.exports = function correctMkdir (path, cb) { function calculateOwner () { if (!effectiveOwner) { - var uid = +process.getuid() - var gid = +process.getgid() + effectiveOwner = { uid: 0, gid: 0 } - if (uid === 0) { - if (process.env.SUDO_UID) uid = +process.env.SUDO_UID - if (process.env.SUDO_GID) gid = +process.env.SUDO_GID - } + if (process.getuid) effectiveOwner.uid = +process.getuid() + if (process.getgid) effectiveOwner.gid = +process.getgid() - effectiveOwner = { uid: uid, gid: gid } + if (effectiveOwner.uid === 0) { + if (process.env.SUDO_UID) effectiveOwner.uid = +process.env.SUDO_UID + if (process.env.SUDO_GID) effectiveOwner.gid = +process.env.SUDO_GID + } } return effectiveOwner @@ -56,17 +56,17 @@ function makeDirectory (path, cb) { log.verbose('makeDirectory', path, 'creation not in flight; initializing') } + var owner = calculateOwner() + if (!process.getuid) { return mkdirp(path, function (er) { log.verbose('makeCacheDir', 'UID & GID are irrelevant on', process.platform) - stats[path] = { uid: 0, gid: 0 } + stats[path] = owner return cb(er, stats[path]) }) } - var owner = calculateOwner() - if (owner.uid !== 0 || !process.env.HOME) { log.silly( 'makeDirectory', path,