TaKO8Ki / frum

A little bit fast and modern Ruby version manager written in Rust
MIT License
628 stars 15 forks source link

Fix use of temporary path to managed binaries #88

Closed bkuhlmann closed 3 years ago

bkuhlmann commented 3 years ago

Overview

When using command -v, I noticed Frum is pointing to temporary paths for all Ruby related binaries. I assume this is a bug?

Steps to Recreate

brew install frum

export FRUM_DIR="$HOME/.cache/frum"
eval "$(frum init)"

frum install 3.0.2
frum global 3.0.2
gem install pennyworth

# Notice the following paths all use temporary directories instead of the Frum cache as defined above.
command -v ruby        # => /var/folders/j1/szrwbp9d1jg351ghw4f7bcym0000gn/T/frum_1956_1627218393720/bin/ruby
command -v pennyworth  # => /var/folders/j1/szrwbp9d1jg351ghw4f7bcym0000gn/T/frum_1956_1627218393720/bin/pennyworth

Desired Behavior

I would expect to see the full path to where the Frum cache is located. So something more along these lines, for example:

$HOME/.cache/frum/versions/3.0.2/lib/ruby/gems/3.0.0/gems/pennyworth-11.1.1/bin

Environment

TaKO8Ki commented 3 years ago

Thank you for opening the issue. It is not a bug. frum uses temp dir to switch ruby versions in the following functions.

https://github.com/TaKO8Ki/frum/blob/b5b7a8acb676da410120adcbc12988b3b6a89db8/src/commands/init.rs#L51-L61

TaKO8Ki commented 3 years ago

@bkuhlmann Do you have any reason why you want to see the full path?

bkuhlmann commented 3 years ago

Hey Takayuki, yep, it's because of several reasons:

I hope that helps? There is a lot of power in seeing the exact paths. It also helps keep my mind sane when trying to understand the difference between the temporary folders and what's in Frum cache. Not having a one-ot-one correlation is definitely hard to reason about or even explain to fellow engineers who are not familiar with Frum.

TaKO8Ki commented 3 years ago

@bkuhlmann

The temp dir frum uses is just a symlink to a specific ruby version directory. So you can see the full path of your Ruby binary like the following workaround. $FRUM_MULTISHELL_PATH is an environment variable and the path to the Ruby version directory you use. fnm, Node.js version manager written in Rust, also uses temp dir to switch Node.js versions and I created frum referencing fnm.

$ echo "$(readlink $FRUM_MULTISHELL_PATH)/bin/ruby"

It also helps keep my mind sane when trying to understand the different between the temporary folders and what's in Frum cache.

As mentioned above, the temp dir is just a symlink. So there is no difference between them.

Do you think it would be useful to improve frum so that frum can show the fully resolved binary path of the current Ruby version like the following?

$ frum path
=> /Users/foo/.frum/aliases/default/bin/ruby
bkuhlmann commented 3 years ago

Takayuki: the temp dir is just a symlink. So there is no difference between them.

Thanks! I will use "$(readlink $FRUM_MULTISHELL_PATH)/bin/ruby" going forward as that will make documentation much easier for me.

Do you think it would be useful to improve frum so that frum can show the fully resolved binary path of the current Ruby version like the following?

Yeah, I think it would be most welcome. Mainly because it won't be surprising for people using standard inspection tools like command or which. Plus, this would match parity with other Ruby Version Managers too and help encourage adoption. :tada:

TaKO8Ki commented 3 years ago

That's good to hear. Thank you for your opinion!