"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/chownr/chownr.js" (8 Mar 2017, 1395 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 module.exports = chownr
    2 chownr.sync = chownrSync
    3 
    4 var fs = require("fs")
    5 , path = require("path")
    6 
    7 function chownr (p, uid, gid, cb) {
    8   fs.readdir(p, function (er, children) {
    9     // any error other than ENOTDIR means it's not readable, or
   10     // doesn't exist.  give up.
   11     if (er && er.code !== "ENOTDIR") return cb(er)
   12     if (er || !children.length) return fs.chown(p, uid, gid, cb)
   13 
   14     var len = children.length
   15     , errState = null
   16     children.forEach(function (child) {
   17       var pathChild = path.resolve(p, child);
   18       fs.lstat(pathChild, function(er, stats) {
   19         if (er)
   20           return cb(er)
   21         if (!stats.isSymbolicLink())
   22           chownr(pathChild, uid, gid, then)
   23         else
   24           then()
   25         })
   26     })
   27     function then (er) {
   28       if (errState) return
   29       if (er) return cb(errState = er)
   30       if (-- len === 0) return fs.chown(p, uid, gid, cb)
   31     }
   32   })
   33 }
   34 
   35 function chownrSync (p, uid, gid) {
   36   var children
   37   try {
   38     children = fs.readdirSync(p)
   39   } catch (er) {
   40     if (er && er.code === "ENOTDIR") return fs.chownSync(p, uid, gid)
   41     throw er
   42   }
   43   if (!children.length) return fs.chownSync(p, uid, gid)
   44 
   45   children.forEach(function (child) {
   46     var pathChild = path.resolve(p, child)
   47     var stats = fs.lstatSync(pathChild)
   48     if (!stats.isSymbolicLink())
   49       chownrSync(pathChild, uid, gid)
   50   })
   51   return fs.chownSync(p, uid, gid)
   52 }