2016-10-10 03:43:44 +02:00
|
|
|
module.exports = isexe
|
|
|
|
isexe.sync = sync
|
|
|
|
|
|
|
|
var fs = require('fs')
|
|
|
|
|
|
|
|
function checkPathExt (path, options) {
|
|
|
|
var pathext = options.pathExt !== undefined ?
|
|
|
|
options.pathExt : process.env.PATHEXT
|
|
|
|
|
|
|
|
if (!pathext) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
pathext = pathext.split(';')
|
|
|
|
if (pathext.indexOf('') !== -1) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
for (var i = 0; i < pathext.length; i++) {
|
|
|
|
var p = pathext[i].toLowerCase()
|
|
|
|
if (p && path.substr(-p.length).toLowerCase() === p) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-04-20 03:09:25 +02:00
|
|
|
function checkStat (stat, path, options) {
|
|
|
|
if (!stat.isSymbolicLink() && !stat.isFile()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return checkPathExt(path, options)
|
|
|
|
}
|
|
|
|
|
2016-10-10 03:43:44 +02:00
|
|
|
function isexe (path, options, cb) {
|
2017-04-20 03:09:25 +02:00
|
|
|
fs.stat(path, function (er, stat) {
|
|
|
|
cb(er, er ? false : checkStat(stat, path, options))
|
2016-10-10 03:43:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function sync (path, options) {
|
2017-04-20 03:09:25 +02:00
|
|
|
return checkStat(fs.statSync(path), path, options)
|
2016-10-10 03:43:44 +02:00
|
|
|
}
|