Merge pull request #110 from panrafal/fix/which

which() should only find files, not directories
This commit is contained in:
Artur Adib 2014-03-07 16:08:29 -05:00
commit ab7bf59b4b

View File

@ -15,6 +15,10 @@ function splitPath(p) {
return p.split(':');
}
function checkPath(path) {
return fs.existsSync(path) && fs.statSync(path).isDirectory() == false;
}
//@
//@ ### which(command)
//@
@ -42,7 +46,7 @@ function _which(options, cmd) {
return; // already found it
var attempt = path.resolve(dir + '/' + cmd);
if (fs.existsSync(attempt)) {
if (checkPath(attempt)) {
where = attempt;
return;
}
@ -50,17 +54,17 @@ function _which(options, cmd) {
if (common.platform === 'win') {
var baseAttempt = attempt;
attempt = baseAttempt + '.exe';
if (fs.existsSync(attempt)) {
if (checkPath(attempt)) {
where = attempt;
return;
}
attempt = baseAttempt + '.cmd';
if (fs.existsSync(attempt)) {
if (checkPath(attempt)) {
where = attempt;
return;
}
attempt = baseAttempt + '.bat';
if (fs.existsSync(attempt)) {
if (checkPath(attempt)) {
where = attempt;
return;
}
@ -69,7 +73,7 @@ function _which(options, cmd) {
}
// Command not found anywhere?
if (!fs.existsSync(cmd) && !where)
if (!checkPath(cmd) && !where)
return null;
where = where || path.resolve(cmd);