mise icon indicating copy to clipboard operation
mise copied to clipboard

`rtx gc|prune|cleanup`

Open jdx opened this issue 1 year ago • 2 comments

we could have a command similar to git gc that would remove unreferenced versions of runtimes. To do this, we need to first have a list of all of the past referenced versions and/or .tool-versions files. We'll need to track this in the cache or something.

jdx avatar Feb 27 '23 02:02 jdx

This has another angle: if you create a python venv, per default it symlinks to the python it uses. Therefore, even if the python is not referenced in any .tool-versions file anymore, it could still be used in a venv. (thats actually the main reason I use rtx/asdf because brew was removing the old python version breaking my venvs.)

jankatins avatar Feb 27 '23 16:02 jankatins

yes, and if people use RTX_<PLUGIN>_VERSION or rtx x <PLUGIN>@<VERSION> this wouldn't be aware and would remove those versions, unless we record those forever.

Right now I'm thinking that's just how it would work. If you use prune you'll potentially remove things you actually use.

Alternatively I could look at the atime of the runtimes and prune things older than 30 days or something. I could also track the env vars and runtime args... lots of options.

jdx avatar Feb 27 '23 16:02 jdx

How about landing a symlink back to any .tool-versions file that was ever used by rtx and gc can check whether the file still exists, and if it does, then use it to reference count appropriately. (This would have the benefit of being able to tell a caller what’s hanging on to the reference.)

mark-thm avatar Feb 28 '23 19:02 mark-thm

That’s roughly what I was thinking but a symlink is a good idea to keep it simple

jdx avatar Feb 28 '23 20:02 jdx

Would be great if the command also displayed which version files were taken in consideration during the cleanup process

sirikon avatar Mar 03 '23 15:03 sirikon

maybe a rtx prune --dry-run would help with that

jdx avatar Mar 03 '23 15:03 jdx

Shell script spaghetti in the meantime: rtx ls | rg -v "⏵" | awk '{$1=$1;print}' | tr ' ' '@' | tr '\n' ' ' | xargs rtx rm Explanation:

rtx ls              | # Lists all installed tools
rg -v "⏵"           | # Filters tools by whether they are selected
awk '{$1=$1;print}' | # Removes leading whitespace
tr ' ' '@'          | # Converts ' ' into '@' (i.e. nodejs 19.7.0 -> [email protected])
tr '\n' ' '         | # Changes the newline-separated list of versions to a space-separated list
xargs rtx rm          # Removes all of the versions

Wyatt-Stanke avatar Mar 03 '23 23:03 Wyatt-Stanke

This is out! Let me know how it works.

jdx avatar Mar 04 '23 01:03 jdx