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
which() should check executability before returning a value #657
Comments
From the docs:
To me, "command" implies something which can be executed. Therefore, it's a bug to point to something which cannot be executed (but, as noted above, Windows and Unix have different definitions of "executability", and we need to make the right decision for each OS). To examine this another way, imagine your $ ls -l ~/first-folder/foo ~/second-folder/foo
-rw-r----- 1 [...] ~/first-folder/foo
-rwxr-x--- 1 [...] ~/second-folder/foo
$ foo # executes second-folder/foo, because first-folder/foo lacks exec bit
$ which foo # if this returns first-folder/foo, that would be a bug
~/second-folder/foo |
@nfischer OK. I'll send you PR soon. |
On Unix, this only matches files with the exec bit set. On Windows, this only matches files which are readable (since Windows has different rules for execution). Fixes #657.
which()
should only return a value if it finds a matching file in the PATH and that file is executable.I'm not sure if it's possible to reliably check executability on Windows, but this should at least be done for unix. This section of the docs suggests a way of using
fs.statSync()
to check this info.The right way would be to also check if the current user matches the
user
,group
, orall
fields as well, but I think this might be tricky. It should be sufficient to just assume that we do have a match, and just do an OR of all three (ex.userCanExecute() || groupCanExecute() || allCanExecute()
).The text was updated successfully, but these errors were encountered: