aquaproj / aqua

Declarative CLI Version manager written in Go. Support Lazy Install, Registry, and continuous update with Renovate. CLI version is switched seamlessly
https://aquaproj.github.io
755 stars 32 forks source link

Command to remove outdated packages/binaries #2942

Open reitzig opened 3 weeks ago

reitzig commented 3 weeks ago

Feature Overview

As a (power πŸ˜‡) user, I want to maintain my user-space, cross-project tooling with aqua without blowing up storage usage over time.

I understand that an automatism is hard to conceive of, due to the highly dynamic and semi-stateless way aqua works. However, a command for me to call would solve my use case; I would just integrate it into my upgrade routine.

Why is the feature needed?

When I frequently upgrade tools installed through aqua, it assembles quite a volume of files. After just a few days of usage, I have:

🐧❯ du -sh ~/.local/share/aquaproj-aqua/
1,2G    /home/raphael/.local/share/aquaproj-aqua/

Meanwhile, a clean install results in

🐧❯ aqua list -a --installed | wc -l
21
🐧❯ du -sh ~/.local/share/aquaproj-aqua
862M    /home/raphael/.local/share/aquaproj-aqua

With a few rather active tools in my list, I expect to need a cleanup routine sooner rather than later.

Workaround

While I can definitely

aqua rm --all

and rely on lazy install, depending on when/where the install triggers, the experience is less than pretty. For instance, with direnv/direnv and starship/starship:

🐧❯ aqua rm --all
INFO[0000] removing all packages                         aqua_version=2.29.0 env=linux/amd64 program=aqua
/home/raphael/.local/share/aquaproj-aqua/pkgs/github_release/github.com/direnv/direnv/v2.34.0/direnv.linux-amd64/direnv.linux-amd64: command not found
- (line 3): 
        "/home/raphael/.local/share/aquaproj-aqua/pkgs/github_release/github.com/direnv/direnv/v2.34.0/direnv.linux-amd64/direnv.linux-amd64" export fish | source;
        ^
in function '__direnv_export_eval'
in event handler: handler for generic event β€œfish_prompt”
INFO[0000] download and unarchive the package            aqua_version=2.29.0 env=linux/amd64 exe_name=starship package_name=starship/starship package_version=v1.19.0 program=aqua registry=standard
[WARN] - (starship::modules::custom): Executing custom command "env | grep -c KUBE" timed out.
[WARN] - (starship::modules::custom): You can set command_timeout in your config to a higher value or set ignore_timeout to true for this module to allow longer-running commands to keep executing.

I guess I could do this as an "atomic" action:

aqua rm --all && aqua install -a

But then I would always re-download all tools, which seems a waste of time and bandwidth.

Example Code

I imagine we could have something like:

$ aqua rm --outdated

This would delete all versions except the latest ones.

(This would, of course, cause re-installs for all projects that pin an older version. For me, that'd be acceptable.)

Note sure how one would encode "delete all versions but the ones pinned in the global config" -- --all means different things to aqua install and aqua rm. πŸ€”

Maybe a dedicated command like

$ aqua clean [--all]

could delete all versions but the once references in the current scope?

Note

I found this, which seems to leave room for future discussions:

You may want to keep the latest version and delete only old versions, but we don't support it now. Lazy Install will reinstall the latest version.

538

So here I am. 😁

suzuki-shunsuke commented 3 weeks ago

Thank you for your proposal.

I think this proposal makes sense.

I think we need to do the following things.

  1. Search the directory AQUA_ROOT_DIR and get the list of installed packages and their versions
  2. Compare versions and get the latest version by each package
  3. Delete old versions

https://aquaproj.github.io/docs/reference/registry-config/#package-types

Another solution is to use a machine with enough storage lol.