diff options
author | isaacs <i@izs.me> | 2012-03-29 02:35:42 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-03-29 02:35:42 +0400 |
commit | 5002c00d63ed9d1cd80eabc69e7972e4894a1848 (patch) | |
tree | 558fddb19529ed1c7fae91a8eb937f1c9a152d6c /node_modules/chownr | |
parent | 74912ecc536f8c63dac9c29a1b4779eec441c51e (diff) |
Add chownr dependency
Diffstat (limited to 'node_modules/chownr')
-rw-r--r-- | node_modules/chownr/README.md | 3 | ||||
-rw-r--r-- | node_modules/chownr/chownr.js | 41 | ||||
-rw-r--r-- | node_modules/chownr/package.json | 38 |
3 files changed, 82 insertions, 0 deletions
diff --git a/node_modules/chownr/README.md b/node_modules/chownr/README.md new file mode 100644 index 000000000..70e9a54a3 --- /dev/null +++ b/node_modules/chownr/README.md @@ -0,0 +1,3 @@ +Like `chown -R`. + +Takes the same arguments as `fs.chown()` diff --git a/node_modules/chownr/chownr.js b/node_modules/chownr/chownr.js new file mode 100644 index 000000000..598b8f844 --- /dev/null +++ b/node_modules/chownr/chownr.js @@ -0,0 +1,41 @@ +module.exports = chownr +chownr.sync = chownrSync + +var fs = require("fs") +, path = require("path") + +function chownr (p, uid, gid, cb) { + fs.readdir(p, function (er, children) { + // any error other than ENOTDIR means it's not readable, or + // doesn't exist. give up. + if (er && er.code !== "ENOTDIR") return cb(er) + if (er || !children.length) return fs.chown(p, uid, gid, cb) + + var len = children.length + , errState = null + children.forEach(function (child) { + chownr(path.resolve(p, child), uid, gid, then) + }) + function then (er) { + if (errState) return + if (er) return cb(errState = er) + if (-- len === 0) return fs.chown(p, uid, gid, cb) + } + }) +} + +function chownrSync (p, uid, gid) { + var children + try { + children = fs.readdirSync(p) + } catch (er) { + if (er && er.code === "ENOTDIR") return fs.chownSync(p, uid, gid) + throw er + } + if (!children.length) return fs.chownSync(p, uid, gid) + + children.forEach(function (child) { + chownrSync(path.resolve(p, child), uid, gid) + }) + return fs.chownSync(p, uid, gid) +} diff --git a/node_modules/chownr/package.json b/node_modules/chownr/package.json new file mode 100644 index 000000000..10e52c4dc --- /dev/null +++ b/node_modules/chownr/package.json @@ -0,0 +1,38 @@ +{ + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "name": "chownr", + "description": "like `chown -R`", + "version": "0.0.1", + "repository": { + "type": "git", + "url": "git://github.com/isaacs/chownr.git" + }, + "main": "chownr.js", + "devDependencies": { + "tap": "0.2", + "mkdirp": "0.3", + "rimraf": "" + }, + "scripts": { + "test": "tap test/*.js" + }, + "_npmUser": { + "name": "isaacs", + "email": "i@izs.me" + }, + "_id": "chownr@0.0.1", + "dependencies": {}, + "optionalDependencies": {}, + "engines": { + "node": "*" + }, + "_engineSupported": true, + "_npmVersion": "1.1.13", + "_nodeVersion": "v0.7.7-pre", + "_defaultsLoaded": true, + "_from": "chownr" +} |