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

Fix init on failure to find PATH automatically #114

Merged
merged 1 commit into from
Nov 20, 2021

Conversation

darkowlzz
Copy link
Contributor

Downloaded bin on a new machine and encountered the following behavior, with debug:

$ bin --debug
   • debug logs enabled
   • Config directory is: /home/ubuntu/.config/bin
   • User PATH is [/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
   • Checking path /usr/local/sbin
   • Error [permission denied] checking path
   • Checking path /usr/local/bin
   • Error [permission denied] checking path
   • Checking path /usr/sbin
   • Error [permission denied] checking path
   • Checking path /usr/bin
   • Error [permission denied] checking path
   • Checking path /sbin
   • Error [permission denied] checking path
   • Checking path /bin
   • Error [permission denied] checking path
   • Checking path /usr/games
   • Error [permission denied] checking path
   • Checking path /usr/local/games
   • Error [permission denied] checking path
   • Checking path /snap/bin
   • Error [permission denied] checking path
   • Could not find a PATH directory automatically, falling back to manual selection

Please specify a download directory: /home/ubuntu/.bin
   • Could not find a PATH directory automatically, falling back to manual selection

Please specify a download directory: /home/ubuntu/Downloads
   • Could not set download directory [/home/ubuntu/Downloads
]: [Error setting download path [stat /home/ubuntu/Downloads: no such file or directory]]
   • Could not find a PATH directory automatically, falling back to manual selection

Please specify a download directory: /home/ubuntu/go
   • Could not find a PATH directory automatically, falling back to manual selection

It enters a loop and never comes out of it.
This change adds a break statement to help break out of the loop.

$ bin
Please specify a download directory: /home/ubuntu/.bin
   • Download path set to /home/ubuntu/.bin


 Path   Version         URL     Status

After fixing the above, encountered an issue when trying to install a binary:

$ bin install github.com/fluxcd/flux2
   • Getting latest release for fluxcd/flux2
   • Starting download of https://github.com/fluxcd/flux2/releases/download/v0.23.0/flux_0.23.0_linux_arm64.tar.gz
11.45 MiB / 11.45 MiB [---------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 3.86 MiB p/s 3s

   ⨯ command failed            error=Error installing binary: open /home/ubuntu/.bin
: file exists

Checked the bin config to find a white space in the default_path:

$ cat ~/.config/bin/config.json
{
    "default_path": "/home/ubuntu/.bin\n",
    "bins": {}
}

Removing the newline from default_path made the binary installation above to succeed and list the installed binary:

$ bin

 Path                           Version         URL                             Status
 /home/ubuntu/.bin/flux         v0.23.0         github.com/fluxcd/flux2         OK

Updated the loop that takes the input PATH to trim whitespace before using it and that fixed
all the problems.

When setting PATH directory manually, because the automatic detection
failed, bin enters a loop and never comes out of it. This change adds a
break after accepting the input and breaks out of the loop.

Also, the input seems to contain a newline at the end, which causes
further installation of binaries to fail due to malformed binary path.
In order to fix it, trimp white spaces from the given input before using
it.
@marcosnils
Copy link
Owner

thanks for the contribution! crafting a release with the fix in a minute!

@marcosnils marcosnils merged commit 143728d into marcosnils:master Nov 20, 2021
@darkowlzz darkowlzz deleted the fix-init-dnld-dir branch November 20, 2021 20:19
@darkowlzz
Copy link
Contributor Author

thanks for the contribution! crafting a release with the fix in a minute!

Great! Thanks, will update and use the new version.

@marcosnils
Copy link
Owner

🚢 thx again!

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 this pull request may close these issues.

2 participants