You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 918B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const fs = require('fs');
  3. const pify = require('pify');
  4. const isExe = (mode, gid, uid) => {
  5. if (process.platform === 'win32') {
  6. return true;
  7. }
  8. const isGroup = gid ? process.getgid && gid === process.getgid() : true;
  9. const isUser = uid ? process.getuid && uid === process.getuid() : true;
  10. return Boolean((mode & 0o0001) ||
  11. ((mode & 0o0010) && isGroup) ||
  12. ((mode & 0o0100) && isUser));
  13. };
  14. module.exports = name => {
  15. if (typeof name !== 'string') {
  16. return Promise.reject(new TypeError('Expected a string'));
  17. }
  18. return pify(fs.stat)(name).then(stats => stats && stats.isFile() && isExe(stats.mode, stats.gid, stats.uid));
  19. };
  20. module.exports.sync = name => {
  21. if (typeof name !== 'string') {
  22. throw new TypeError('Expected a string');
  23. }
  24. const stats = fs.statSync(name);
  25. return stats && stats.isFile() && isExe(stats.mode, stats.gid, stats.uid);
  26. };
  27. module.exports.checkMode = isExe;