1 module.exports = chmodr
2 chmodr.sync = chmodrSync
5 var path = require("path")
7 function chmodr (p, mode, cb) {
8 fs.lstat(p, function (er, stats) {
11 if (stats.isSymbolicLink())
13 if (stats.isDirectory())
14 return chmodrDir(p, mode, cb)
15 return fs.chmod(p, mode, cb)
19 function chmodrDir (p, mode, cb) {
20 fs.readdir(p, function (er, children) {
25 return fs.chmod(p, dirMode(mode), cb)
27 var len = children.length
29 children.forEach(function (child) {
30 chmodr(path.resolve(p, child), mode, then)
33 // return first error, but not until all are finished,
34 // so we don't keep performing FS operations after the cb
43 return fs.chmod(p, dirMode(mode), cb)
49 function chmodrSync (p, mode) {
50 var stats = fs.lstatSync(p)
51 if (stats.isSymbolicLink())
53 if (stats.isDirectory())
54 return chmodrDirSync(p, mode)
56 return fs.chmodSync(p, mode)
59 function chmodrDirSync (p, mode) {
60 fs.readdirSync(p).forEach(function (child) {
61 chmodrSync(path.resolve(p, child), mode)
63 return fs.chmodSync(p, dirMode(mode))
66 // If a party has r, add x
67 // so that dirs are listable
68 function dirMode(mode) {