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:
authorisaacs <i@izs.me>2012-03-13 20:48:42 +0400
committerisaacs <i@izs.me>2012-03-27 11:17:51 +0400
commit7fb3d9aaf5e9617269245876a4172b4919873a16 (patch)
tree0c24ad6a200f8fb85b3f0c733c3995bdb5815912
parentd4b80af373175a495288a8fd3e03cac406d1b3e2 (diff)
Abstract out 'uid-number' to a separate dependency
-rw-r--r--lib/npm.js2
-rw-r--r--lib/utils/mkdir-p.js2
-rw-r--r--lib/utils/tar.js2
-rw-r--r--lib/utils/uid-number.js55
-rw-r--r--node_modules/uid-number/README.md17
-rwxr-xr-xnode_modules/uid-number/get-uid-gid.js (renamed from bin/npm-get-uid-gid.js)8
-rw-r--r--node_modules/uid-number/package.json34
-rw-r--r--node_modules/uid-number/uid-number.js54
-rw-r--r--package.json3
9 files changed, 118 insertions, 59 deletions
diff --git a/lib/npm.js b/lib/npm.js
index afce0f9f2..3e4addf64 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -25,7 +25,7 @@ var EventEmitter = require("events").EventEmitter
, which = require("which")
, semver = require("semver")
, findPrefix = require("./utils/find-prefix.js")
- , getUid = require("./utils/uid-number.js")
+ , getUid = require("uid-number")
, mkdir = require("./utils/mkdir-p.js")
, slide = require("slide")
, chain = slide.chain
diff --git a/lib/utils/mkdir-p.js b/lib/utils/mkdir-p.js
index cc2b465fb..2d9b9ee9f 100644
--- a/lib/utils/mkdir-p.js
+++ b/lib/utils/mkdir-p.js
@@ -4,7 +4,7 @@ var log = require("./log.js")
, path = require("path")
, npm = require("../npm.js")
, exec = require("./exec.js")
- , uidNumber = require("./uid-number.js")
+ , uidNumber = require("uid-number")
, umask = process.umask()
, umaskOrig = umask
, addedUmaskExit = false
diff --git a/lib/utils/tar.js b/lib/utils/tar.js
index 27313f7d8..3db1f16a6 100644
--- a/lib/utils/tar.js
+++ b/lib/utils/tar.js
@@ -5,7 +5,7 @@ var npm = require("../npm.js")
, fs = require("graceful-fs")
, path = require("path")
, log = require("./log.js")
- , uidNumber = require("./uid-number.js")
+ , uidNumber = require("uid-number")
, rm = require("rimraf")
, readJson = require("./read-json.js")
, relativize = require("./relativize.js")
diff --git a/lib/utils/uid-number.js b/lib/utils/uid-number.js
deleted file mode 100644
index 375627553..000000000
--- a/lib/utils/uid-number.js
+++ /dev/null
@@ -1,55 +0,0 @@
-module.exports = uidNumber
-
-// This module calls into bin/npm-get-uid-gid.js, which sets the
-// uid and gid to the supplied argument, in order to find out their
-// numeric value. This can't be done in the main node process,
-// because otherwise npm would be running as that user.
-
-var exec = require("./exec.js")
- , path = require("path")
- , log = require("./log.js")
- , constants = require("constants")
- , npm = require("../npm.js")
- , uidSupport = process.getuid && process.setuid
- , uidCache = {}
- , gidCache = {}
-
-function uidNumber (uid, gid, cb) {
- if (!uidSupport || npm.config.get("unsafe-perm")) return cb()
- if (typeof cb !== "function") cb = gid, gid = null
- if (typeof cb !== "function") cb = uid, uid = null
- if (gid == null) gid = process.getgid()
- if (uid == null) uid = process.getuid()
- if (!isNaN(gid)) gid = +gid
- if (!isNaN(uid)) uid = +uid
-
- if (uidCache[uid]) uid = uidCache[uid]
- if (gidCache[gid]) gid = gidCache[gid]
-
- if (typeof gid === "number" && typeof uid === "number") {
- return cb(null, uid, gid)
- }
-
- var getter = path.join(__dirname, "..", "..", "bin", "npm-get-uid-gid.js")
- return exec( process.execPath, [getter, uid, gid], process.env, false
- , null, process.getuid(), process.getgid()
- , function (er, code, out, err) {
- if (er) return log.er(cb, "Could not get uid/gid "+err)(er)
- log.silly(out, "output from getuid/gid")
- out = JSON.parse(out+"")
- if (out.error) {
- if (!npm.config.get("unsafe-perm")) {
- var er = new Error(out.error)
- er.errno = out.errno
- return cb(er)
- } else {
- return cb(null, +process.getuid(), +process.getgid())
- }
- }
- if (isNaN(out.uid) || isNaN(out.gid)) return cb(new Error(
- "Could not get uid/gid: "+JSON.stringify(out)))
- uidCache[uid] = out.uid
- uidCache[gid] = out.gid
- cb(null, out.uid, out.gid)
- })
-}
diff --git a/node_modules/uid-number/README.md b/node_modules/uid-number/README.md
new file mode 100644
index 000000000..81166753a
--- /dev/null
+++ b/node_modules/uid-number/README.md
@@ -0,0 +1,17 @@
+Use this module to convert a username/groupname to a uid/gid number.
+
+Usage:
+
+```
+npm install uid-number
+```
+
+Then, in your node program:
+
+```javascript
+var uidNumber = require("uid-number")
+uidNumber("isaacs", function (er, uid, gid) {
+ // gid is null because we didn't ask for a group name
+ // uid === 24561 because that's my number.
+})
+```
diff --git a/bin/npm-get-uid-gid.js b/node_modules/uid-number/get-uid-gid.js
index 390e0f2fc..0b391748a 100755
--- a/bin/npm-get-uid-gid.js
+++ b/node_modules/uid-number/get-uid-gid.js
@@ -1,3 +1,11 @@
+if (module !== require.main) {
+ throw new Error("This file should not be loaded with require()")
+}
+
+if (!process.getuid || !process.getgid) {
+ throw new Error("this file should not be called without uid/gid support")
+}
+
var argv = process.argv.slice(2)
, user = argv[0] || process.getuid()
, group = argv[1] || process.getgid()
diff --git a/node_modules/uid-number/package.json b/node_modules/uid-number/package.json
new file mode 100644
index 000000000..3c0592cb6
--- /dev/null
+++ b/node_modules/uid-number/package.json
@@ -0,0 +1,34 @@
+{
+ "author": {
+ "name": "Isaac Z. Schlueter",
+ "email": "i@izs.me",
+ "url": "http://blog.izs.me/"
+ },
+ "name": "uid-number",
+ "description": "Convert a username/group name to a uid/gid number",
+ "version": "0.0.3",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/isaacs/uid-number.git"
+ },
+ "main": "uid-number.js",
+ "dependencies": {},
+ "devDependencies": {},
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ },
+ "_npmUser": {
+ "name": "isaacs",
+ "email": "i@izs.me"
+ },
+ "_id": "uid-number@0.0.3",
+ "_engineSupported": true,
+ "_npmVersion": "1.1.12",
+ "_nodeVersion": "v0.7.7-pre",
+ "_defaultsLoaded": true,
+ "dist": {
+ "shasum": "be40aeab1db6ba45d2344d4ed6015109fc9d98d4"
+ },
+ "_from": "uid-number@0.0.3"
+}
diff --git a/node_modules/uid-number/uid-number.js b/node_modules/uid-number/uid-number.js
new file mode 100644
index 000000000..93f372bb9
--- /dev/null
+++ b/node_modules/uid-number/uid-number.js
@@ -0,0 +1,54 @@
+module.exports = uidNumber
+
+// This module calls into get-uid-gid.js, which sets the
+// uid and gid to the supplied argument, in order to find out their
+// numeric value. This can't be done in the main node process,
+// because otherwise node would be running as that user from this
+// point on.
+
+var child_process = require("child_process")
+ , path = require("path")
+ , uidSupport = process.getuid && process.setuid
+ , uidCache = {}
+ , gidCache = {}
+
+function uidNumber (uid, gid, cb) {
+ if (!uidSupport) return cb()
+ if (typeof cb !== "function") cb = gid, gid = null
+ if (typeof cb !== "function") cb = uid, uid = null
+ if (gid == null) gid = process.getgid()
+ if (uid == null) uid = process.getuid()
+ if (!isNaN(gid)) gid = uidCache[gid] = +gid
+ if (!isNaN(uid)) uid = uidCache[uid] = +uid
+
+ if (uidCache.hasOwnProperty(uid)) uid = uidCache[uid]
+ if (gidCache.hasOwnProperty(gid)) gid = gidCache[gid]
+
+ if (typeof gid === "number" && typeof uid === "number") {
+ return process.nextTick(cb.bind(null, null, uid, gid))
+ }
+
+ var getter = require.resolve("./get-uid-gid.js")
+
+ child_process.execFile( process.execPath
+ , [getter, uid, gid]
+ , function (code, out, err) {
+ if (er) return cb(new Error("could not get uid/gid\n" + err))
+ try {
+ out = JSON.parse(out+"")
+ } catch (ex) {
+ return cb(ex)
+ }
+
+ if (out.error) {
+ var er = new Error(out.error)
+ er.errno = out.errno
+ return cb(er)
+ }
+
+ if (isNaN(out.uid) || isNaN(out.gid)) return cb(new Error(
+ "Could not get uid/gid: "+JSON.stringify(out)))
+
+ cb(null, uidCache[uid] = +out.uid, uidCache[gid] = +out.gid)
+ })
+}
diff --git a/package.json b/package.json
index 14e9a50e0..57432e498 100644
--- a/package.json
+++ b/package.json
@@ -54,7 +54,8 @@
"read": "0",
"lru-cache": "1",
"node-gyp": "~0.3.7",
- "fstream-npm": "0.0"
+ "fstream-npm": "0.0",
+ "uid-number": "0.0"
},
"bundleDependencies": [
"slide",