Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

mode.js 909B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. module.exports = isexe
  2. isexe.sync = sync
  3. var fs = require('fs')
  4. function isexe (path, options, cb) {
  5. fs.stat(path, function (er, stat) {
  6. cb(er, er ? false : checkStat(stat, options))
  7. })
  8. }
  9. function sync (path, options) {
  10. return checkStat(fs.statSync(path), options)
  11. }
  12. function checkStat (stat, options) {
  13. return stat.isFile() && checkMode(stat, options)
  14. }
  15. function checkMode (stat, options) {
  16. var mod = stat.mode
  17. var uid = stat.uid
  18. var gid = stat.gid
  19. var myUid = options.uid !== undefined ?
  20. options.uid : process.getuid && process.getuid()
  21. var myGid = options.gid !== undefined ?
  22. options.gid : process.getgid && process.getgid()
  23. var u = parseInt('100', 8)
  24. var g = parseInt('010', 8)
  25. var o = parseInt('001', 8)
  26. var ug = u | g
  27. var ret = (mod & o) ||
  28. (mod & g) && gid === myGid ||
  29. (mod & u) && uid === myUid ||
  30. (mod & ug) && myUid === 0
  31. return ret
  32. }