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

command treats directories found on the $PATH as commands #2126

Open
quexxon opened this issue Nov 19, 2024 · 3 comments
Open

command treats directories found on the $PATH as commands #2126

quexxon opened this issue Nov 19, 2024 · 3 comments

Comments

@quexxon
Copy link
Collaborator

quexxon commented Nov 19, 2024

This affects OSH/YSH. Discovered due to a .NET package in my path with a tr directory for translations.

osh-0.24.0$ which cat
/usr/bin/cat
osh-0.24.0$ command -v cat
/usr/bin/cat
osh-0.24.0$ = PATH => split(':')[0]
(Str)   '/home/will/.cargo/bin'
osh-0.24.0$ mkdir ~/.cargo/bin/cat
osh-0.24.0$ osh
osh-0.24.0$ which cat
/usr/bin/cat
osh-0.24.0$ command -v cat
/home/will/.cargo/bin/cat
osh-0.24.0$ cat
  cat
  ^~~
[ interactive ]:3: Can't execute '/home/will/.cargo/bin/cat': Permission denied
@quexxon
Copy link
Collaborator Author

quexxon commented Nov 19, 2024

I think the issue is here. That should check for the executable mode bit and check that the file is a regular file. I can take a stab at this.

@andychu
Copy link
Contributor

andychu commented Nov 19, 2024

Oh yes! Thanks for noticing this

That code is for command -v I think, which does need to be changed


And then also executor.py LookupExecutable() needs to be changed

I think that needs the same file check, regardless of exec_required ?

I appreciate any help!


Also let me know if you need help with spec tests

For these it should be fairly satisfying. The tests start in a tempdir, so you can do

mkdir -p cat
PATH=. cat

or something like that

And then you assert status and/or stdout

https://github.com/oils-for-unix/oils/wiki/Spec-Tests

@andychu
Copy link
Contributor

andychu commented Nov 19, 2024

I also use grep to navigate the code and tests, like

grep LookupExecutable */*.py

and

grep 'command -v' spec/*.test.sh

and so forth

There is a cheat sheet here - https://github.com/oils-for-unix/oils/wiki/Oil-Dev-Cheat-Sheet

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

No branches or pull requests

2 participants