Skip to content

Commit

Permalink
Check for sudo being ok based on node version
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Feb 8, 2011
1 parent 18166ae commit a997b34
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var EventEmitter = require("events").EventEmitter
, path = require("path")
, abbrev = require("./lib/utils/abbrev")
, which = require("./lib/utils/which")
, semver = require("./lib/utils/semver")

npm.commands = {}
npm.ELIFECYCLE = {}
Expand Down Expand Up @@ -196,4 +197,16 @@ Object.defineProperty(npm, "tmp",
})

// platforms without uid/gid support are assumed to be in unsafe-perm mode.
if (!process.getuid) npm.config.set("unsafe-perm", true)
var sudoOk = !semver.lt(process.version, '0.3.5')
if (!process.getuid || !sudoOk) {
npm.config.set("unsafe-perm", true)
}
if (process.getuid && process.getuid() === 0 && !sudoOk) {
process.nextTick(function () {
log([""
,"Please upgrade to node 0.3.5 or higher"
,"if you are going to be running npm as root."
,"It is not safe otherwise."
,""].join("\n"), "", "error")
})
}

0 comments on commit a997b34

Please sign in to comment.