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

Detect and warn against changes in ~/.cargo/registry #15078

Closed
HKalbasi opened this issue Jan 17, 2025 · 4 comments
Closed

Detect and warn against changes in ~/.cargo/registry #15078

HKalbasi opened this issue Jan 17, 2025 · 4 comments
Labels
A-caching Area: caching of dependencies, repositories, and build artifacts A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@HKalbasi
Copy link
Member

Problem

It is easy to accidentally change files in the ~/.cargo/registry, for example by going to definition of a library and changing its code. Also, newcomers might intentionally change those files and expect them to take effect.

Proposed Solution

  1. Detect if some file is changed in that directory, e.g. by comparing mtime.
  2. Warn user against changes in this directory, help them to use path dependency or patch.crates-io if they really want to change their dependencies.
  3. Remove and redownload the modified files.

Notes

It might also be a good idea to make the directory read only and only user cargo can change it, but it is harder to do it in a cross platform way I guess.

@HKalbasi HKalbasi added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Jan 17, 2025
@weihanglo
Copy link
Member

While its title is “make cache read-only”, the major thread of preventing user edits of registry dependencies is #9455.

Detect if some file is changed in that directory, e.g. by comparing mtime.

If we are going to add a new mechanism, I would avoid mtime. It has problems like imprecise on some filesystem and docker, but agree its performance is quite nice. Computing checksums might also be a possible solution, see #9455 (comment) and this internal forum thread.

In the meanwhile, it seems possible to do it via IDE-specific configurations like rust-lang/rust-analyzer#5847.

@weihanglo weihanglo added A-diagnostics Area: Error and warning messages generated by Cargo itself. A-caching Area: caching of dependencies, repositories, and build artifacts S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-triage Status: This issue is waiting on initial triage. labels Jan 17, 2025
@weihanglo
Copy link
Member

Unsure whether this should be keep open separately or not. Seems like a duplicate of #9455 but with a specific solution in mind.

@epage
Copy link
Contributor

epage commented Jan 17, 2025

As its one conversation, let's close this so that conversation happens in one place.

@weihanglo
Copy link
Member

Fair enough. Close in favour of #9455

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 A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

3 participants