-
-
Save kpturner/618f738f12bf8740c144 to your computer and use it in GitHub Desktop.
/QOpenSys/QIBM/ProdData/Node/ lib/node_modules/npm/node_modules/chownr/chownr.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment