"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/isexe/mode.js" (8 Mar 2017, 814 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 = isexe
    2 isexe.sync = sync
    3 
    4 var fs = require('fs')
    5 
    6 function isexe (path, options, cb) {
    7   fs.stat(path, function (er, st) {
    8     cb(er, er ? false : checkMode(st, options))
    9   })
   10 }
   11 
   12 function sync (path, options) {
   13   return checkMode(fs.statSync(path), options)
   14 }
   15 
   16 function checkMode (stat, options) {
   17   var mod = stat.mode
   18   var uid = stat.uid
   19   var gid = stat.gid
   20 
   21   var myUid = options.uid !== undefined ?
   22     options.uid : process.getuid && process.getuid()
   23   var myGid = options.gid !== undefined ?
   24     options.gid : process.getgid && process.getgid()
   25 
   26   var u = parseInt('100', 8)
   27   var g = parseInt('010', 8)
   28   var o = parseInt('001', 8)
   29   var ug = u | g
   30 
   31   var ret = (mod & o) ||
   32     (mod & g) && gid === myGid ||
   33     (mod & u) && uid === myUid ||
   34     (mod & ug) && myUid === 0
   35 
   36   return ret
   37 }