Cargo should detect changes in dependency source files

Here's an unfortunate scenario that is very easy to fall into:

  1. In your editor you have opened one or more files from ~/.cargo/registry/src, perhaps by navigating to source code in one of your dependencies.
  2. You make some broad changes in your editor (possibly with search and replace), and inadvertently change one of these external source files.
  3. You end up reverting your local changes with git reset --hard.
  4. Unbeknownst to you, that dependency is still modified, and fails whenever you try to build.
  5. cargo clean does not fix it.

It would be helpful if Cargo could somehow detect or prevent this problem. Some ideas, with the most desirable first.

  • Cargo always does a hash compare of dependency sources before building.
  • When downloading sources, the files are made read-only.
  • cargo clean reverts any changes in dependency source code.

cc Consider making the `src` cache read-only. · Issue #9455 · rust-lang/cargo · GitHub

2 Likes
2 Likes

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.