Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Abstract out 'uid-number' to a separate dependency

  • Loading branch information...
commit 7fb3d9aaf5e9617269245876a4172b4919873a16 1 parent d4b80af
@isaacs isaacs authored
View
2  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
View
2  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
View
2  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")
View
55 lib/utils/uid-number.js
@@ -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)
- })
-}
View
17 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.
+})
+```
View
8 bin/npm-get-uid-gid.js → 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()
View
34 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"
+}
View
54 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)
+ })
+}
View
3  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",
Please sign in to comment.
Something went wrong with that request. Please try again.