rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.67k stars 2.41k forks source link

gc: Determine CLI design for manual cleaning #13060

Open ehuss opened 10 months ago

ehuss commented 10 months ago

The current implementation from https://github.com/rust-lang/cargo/pull/12634 exposes a cargo clean gc subcommand to handle manually cleaning cache data. It is not clear what the final CLI design should be (and it is not clear exactly what the user scenarios are for when they would want to take manual control). This issue is tracking for determining what the CLI should look like. There are few different considerations:

epage commented 10 months ago

Potential sources of prior of other tools with cache management

Apparently buck2 and Turborepo grow unbounded

epage commented 10 months ago

Quick scan of brew

One complaint that came up was "brew cleanup has not been run in 30 days, running now" ... and then proceeds to run an interminable process in the middle of you attempting to do something else." (mastadon)

epage commented 10 months ago

We should probably step back and enumerate what the required use cases are and the "if it works" use cases.

juliusl commented 4 months ago

I like the way pnpm approaches this,

https://pnpm.io/cli/store

Running pnpm store prune is not harmful and has no side effects on your projects. If future installations require removed packages, pnpm will download them again.

It is best practice to run pnpm store prune occasionally to clean up the store, but not too frequently. Sometimes, unreferenced packages become required again. This could occur when switching branches and installing older dependencies, in which case pnpm would need to re-download all removed packages, briefly slowing down the installation process.

juliusl commented 4 months ago

Regarding the concern of deleting crates that might still be in use, I like how rushjs asks you to pass an --unsafe flag to it's purge command,

https://rushjs.io/pages/commands/rush_purge/

 --unsafe    (UNSAFE!) Also delete shared files such as the package manager
              instances stored in the ".rush" folder in the user's home
              directory. This is a more aggressive fix that is NOT SAFE to
              run in a live environment because it will cause other
              concurrent Rush processes to fail.
epage commented 4 months ago

@juliusl

https://pnpm.io/cli/store

it sounds like pnpm store prune removes everything that isn't referenced, regardless of age or size.

In #13137 I bring up the idea to build on top of the work to track workspaces in #13136 so we pin entries not in current lockfiles.

To extend this to clean up everything has the risk is if a project is transient (e.g. removable media) or moved but a new command wasn't run to register the new location. If its manually done with a command, rather than part of the auto-gc, then that might be reasonable, especially if we swap the logic and have a --execute flag rather than a --dry-run flag.

Regarding the concern of deleting crates that might still be in use, I like how rushjs asks you to pass an --unsafe flag to it's purge command,

I don't think an --unsafe flag is as relevant. For any shared directories, we use filesystem locks to ensure consistent reads/writes.

Any "in use" concerns we have are more about "relevant to the user" and not "file descriptors are open" and is mostly relevant for slow networks/systems and offline usage (I don't want a rarely used dependency being removed just before I go on an airplane to do development offline).