Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns a directory if it is in path and executable bit is set #37

Closed
ptierno opened this issue Aug 25, 2016 · 2 comments
Closed

Returns a directory if it is in path and executable bit is set #37

ptierno opened this issue Aug 25, 2016 · 2 comments

Comments

@ptierno
Copy link

ptierno commented Aug 25, 2016

I ran into an issue where i had a directory in my path which contained a subdirectory. While using which to find an actual executable, it returned the path to the directory instead since it was first in the path:

➜  which ls -l
total 0
drwxr-xr-x  2 ptierno  staff  68 Aug 25 19:02 directory
➜  which export PATH=`pwd`:$PATH
➜  which node
> var which = require('which');
undefined
>
> which.sync('directory')
'/Users/ptierno/which/directory'                                                                                                                                                    

If I remove the executable bit from the directory then the directory doesnt get returned (which is what I would expect).

➜  which chmod -x directory
➜  which node
> var which = require('which');
undefined
> which.sync('directory')
Error: not found: directory
    at getNotFoundError (/Users/ptierno/node_modules/which/which.js:14:12)
    at Function.whichSync [as sync] (/Users/ptierno/node_modules/which/which.js:132:9)
    at repl:1:7
    at REPLServer.defaultEval (repl.js:272:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:441:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:188:7)
    at REPLServer.Interface._onLine (readline.js:224:10)
>

Might be a good idea to do a check to ensure the value being returned is an actual executable file and not a directory.

@isaacs
Copy link
Contributor

isaacs commented Mar 23, 2017

Updating isexe made which's tests break on Windows, so this isn't quite finished or ready to ship yet. I'll try to investigate this soon.

@isaacs
Copy link
Contributor

isaacs commented Mar 23, 2017

Fixed. Not sure how or if the tests ever passed on Windows, without d24dc05.

@isaacs isaacs closed this as completed Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants