Sha256: 3939e43e26cda404ccd3e969b587cb2f1228ac001799886eb515a3e3a217c413

Contents?: true

Size: 1.61 KB

Versions: 62

Compression:

Stored size: 1.61 KB

Contents

module.exports = chmodr
chmodr.sync = chmodrSync

var fs = require("fs")
var path = require("path")

function chmodr (p, mode, cb) {
  fs.lstat(p, function (er, stats) {
    if (er)
      return cb(er)
    if (stats.isSymbolicLink())
      return cb()
    if (stats.isDirectory())
      return chmodrDir(p, mode, cb)
    return fs.chmod(p, mode, cb)
  })
}

function chmodrDir (p, mode, cb) {
  fs.readdir(p, function (er, children) {
    if (er)
      return cb(er)

    if (!children.length)
      return fs.chmod(p, dirMode(mode), cb)

    var len = children.length
    var errState = null
    children.forEach(function (child) {
      chmodr(path.resolve(p, child), mode, then)
    })

    // return first error, but not until all are finished,
    // so we don't keep performing FS operations after the cb
    function then (er) {
      len = len - 1
      if (er && !errState)
        errState = er
      if (len === 0) {
        if (errState)
          return cb(errState)
        else
          return fs.chmod(p, dirMode(mode), cb)
      }
    }
  })
}

function chmodrSync (p, mode) {
  var stats = fs.lstatSync(p)
  if (stats.isSymbolicLink())
    return
  if (stats.isDirectory())
    return chmodrDirSync(p, mode)
  else
    return fs.chmodSync(p, mode)
}

function chmodrDirSync (p, mode) {
  fs.readdirSync(p).forEach(function (child) {
    chmodrSync(path.resolve(p, child), mode)
  })
  return fs.chmodSync(p, dirMode(mode))
}

// If a party has r, add x
// so that dirs are listable
function dirMode(mode) {
  if (mode & 0400)
    mode |= 0100
  if (mode & 040)
    mode |= 010
  if (mode & 04)
    mode |= 01
  return mode
}

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.5 node_modules/bower/node_modules/chmodr/chmodr.js
trusty-festivity-extension-2.5.4 node_modules/bower/node_modules/chmodr/chmodr.js