[pre-rfc] Mark subdirs of ~/.cargo with CACHEDIR.TAG

[Pre-RFC] Put CACHEDIR.TAG into target/ - #11 by kornel previously led to Cargo inserting a CACHEDIR.TAG file into /target so that it can, for example, be automatically ignored by backup programs.

Could we also do that for the subdirectories of ~/.cargo that are disposable caches of remote resources?

Concretely it looks like that would be true for ~/.cargo/git and ~/.cargo/registry.

3 Likes

Ideally we'd do this by putting those files in ~/.cache, but that has a long and storied history of its own.

So in the interim, yes, CACHEDIR.TAG would be an improvement.

2 Likes

Thanks! What would be an appropriate next step for me to make a change for this? Can I just send a PR?

I would start by enumerating the directories in ~/.cargo and which ones you think would be appropriate to treat as cache directories. Then submit that list as an issue on the cargo repository for review. (Also feel free to ping #t-cargo on Zulip once you've filed that issue.) Once that list gets reviewed, then a PR would be appropriate.

That way, we don't iterate on the list of directories in the PR.

3 Likes

Which essential files does the folder even contain? I have set export $CARGO_HOME=$XDG_CACHE_HOME/cargo years ago and not noticed any issues. Therefore wouldn't it suffice to simply put the CACHEDIR.TAG on the top level?

~/.cargo/bin/ contains every binary installed by cargo install. In theory perhaps they can all be recreated, but not trivially: they might have come from local trees, or now-pulled crates. I think it's reasonable to back them up: the user might care to get back the same version.

Maybe eventually those binaries should move to a different directory, or be left behind if the rest moves into ~/.cache.

~/.cargo/config, ~/.cargo/credentials contain small amount of user config that should be backed up.

1 Like

OK thanks, done: Mark `~/.cargo` or some subdirectories with `CACHEDIR.TAG` · Issue #10457 · rust-lang/cargo · GitHub