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

bug: empty $plugins_path dir gives '*' as a plugin #1022

Closed
andreineculau opened this issue Aug 10, 2021 · 2 comments
Closed

bug: empty $plugins_path dir gives '*' as a plugin #1022

andreineculau opened this issue Aug 10, 2021 · 2 comments
Labels

Comments

@andreineculau
Copy link

Describe the Bug

Many commands e.g. asdf plugin list will do if ls "$plugins_path"; then for plugin_path in "$plugins_path/*"; do plugin_name=$(basename "$plugin_path") ...

In case $plugins_path doesn't exist, it works as expected.
In case it does exist, but it's empty, "$plugins_path/*" will expand to the literal, and produce $plugin_name='*'


My suggestion would be to check for if [ -n "$(ls -A "$plugins_path" 2>/dev/null)" ]; then ... but I refrained from submitting a PR because I'm a 1h-asdf-newbie, and I can't be certain of your cross-platform requirements e.g. -A is available on BSD and GNU, but it's not POSIX AFAIK. Based on that, other solutions might be more appropriate.

PS: similar if ls ...; then for ... checks and loops appear in the codebase, and they are behave similarly as the instance above, so fixes could/should be applied uniformly across the codebase.

Steps to Reproduce

# install vanilla asdf e.g. `brew install asdf`

asdf plugin add nodejs
asdf plugin remove nodejs

ls -a ${ASDF_DATA_DIR:-${HOME}}/plugins/ # should be empty

Expected Behaviour

No plugins found.

Actual Behaviour

One plugin found '*'.

Environment

OS:
Darwin andrei-macpro15.local 19.6.0 Darwin Kernel Version 19.6.0: Thu May  6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64 x86_64 i386 MacBookPro10,1 Darwin

SHELL:
zsh 5.8 (x86_64-apple-darwin19.6.0)

ASDF VERSION:
v0.8.1

ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/usr/local/opt/asdf

ASDF INSTALLED PLUGINS:
*

asdf plugins affected (if relevant)

No response

@Stratus3D Stratus3D added this to the v0.9.1 milestone Dec 3, 2021
@threkk
Copy link
Contributor

threkk commented Jan 4, 2022

I am not a bash expert either but I have submitted a few patches already. The unit tests, the development scripts and specially the Github Actions pipelines make contributing to asdf a piece of cake. I suggest you to give it a try to your solution and if you get all of them green, I am sure it will be a good solution.

@andreineculau
Copy link
Author

@threkk hehe Thanks but I somewhat doubt that tests would catch what I'm looking for.

but github-searching for "POSIX" in this repo took me to #1078 (comment) , so now I know that POSIX wins 👏

Upon further investigation, it looks like @Stratus3D fixed this more elegantly that I would have in #1141 🙏 so I'll close this issue.

FWIW I was thinking of

-    if ls "$plugins_path" &>/dev/null; then
+    if ls "$plugins_path/"* &>/dev/null; then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants