Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark ~/.cargo or some subdirectories with CACHEDIR.TAG #10457

Closed
sourcefrog opened this issue Mar 4, 2022 · 2 comments · Fixed by #10553
Closed

Mark ~/.cargo or some subdirectories with CACHEDIR.TAG #10457

sourcefrog opened this issue Mar 4, 2022 · 2 comments · Fixed by #10553
Assignees
Labels
A-caching Area: caching of dependencies, repositories, and build artifacts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@sourcefrog
Copy link
Contributor

sourcefrog commented Mar 4, 2022

Problem

~/.cargo can be fairly large: 4.4G on the machine where I'm writing this, and it takes ~10s to walk.

Most of the content is copies of registries and source trees, which can be downloaded again, so in most situations it doesn't need to be backed up.

CACHEDIR.TAG https://bford.info/cachedir/ is a standard way of marking directories containing caches of information stored elsewhere, so that they can be excluded from backups, etc.

In the Rust ecosystem there is a cachedir crate to detect and insert these marks. At least one Rust backup tool, Conserve, excludes directories marked with CACHEDIR.TAG (using that library), as do other tools not written in Rust.

Proposed Solution

In short: Cargo should insert CACHEDIR.TAG files into either ~/.cargo itself, or some subdirectories.

This would be consistent with how target directories are now marked.

Which directories?

One subsidiary decision is whether to mark the whole of ~/.cargo or only some subdirectories. Most of it does seem to be a cache. However ~/.cargo/bin contains binaries from cargo install, and they may not be trivially recreatable, for example if they were built from cargo install --path, or if the user cares about restoring the exact version.

So, it would be more conservative to mark only git and registry.

When to mark them?

target seems to only get marked when it is first created.

This doesn't seem like a good fit for ~/.cargo, which already exists on every machine where people use the Rust toolchain, and should never normally be recreated.

So I'd argue it would be reasonable for Cargo to mark these directories every time it runs an operation that updates them, if the mark does not already exist.

Notes

See also:

@sourcefrog sourcefrog added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Mar 4, 2022
@joshtriplett
Copy link
Member

We discussed this in today's @rust-lang/cargo meeting, and this sounds reasonable to us! Please go ahead and send a PR for this, marking those two subdirectories (git and registry).

@sourcefrog
Copy link
Contributor Author

Thanks!

@rustbot claim

@ehuss ehuss added the A-caching Area: caching of dependencies, repositories, and build artifacts label Apr 8, 2022
bors added a commit that referenced this issue Apr 27, 2022
Mark .cargo/git and .cargo/registry as cache dirs

Fixes #10457

### What does this PR try to resolve?

As we previously discussed in #10457 this marks `~/.cargo/git` and `~/.cargo/registry` as not to be included in backups, and not subject to content indexing. These directories can be fairly large and frequently changed, and should only contain content that can be re-downloaded if necessary.

### How should we test and review this PR?

I did two manual tests:

1. Using the binary built from this tree, run `cargo update` in a source tree that has a git dependency, and observe that afterwards, there is a `CACHEDIR.TAG` in `~/.cargo/git`.
2. Similarly, run `cargo update` and observe that there's a `CACHEDIR.TAG` in `~/.cargo/registry`.

(I ran this on Linux. This code should also trigger OS-specific behavior on macOS and Windows that's the same as is currently applied to `target/`.)

I added some test assertions.
@bors bors closed this as completed in ce9a6ab Apr 27, 2022
Hezuikn pushed a commit to Hezuikn/cargo that referenced this issue Sep 22, 2022
Hezuikn pushed a commit to Hezuikn/cargo that referenced this issue Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-caching Area: caching of dependencies, repositories, and build artifacts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants