-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
cargo vendor --versioned-dirs
doesn't notice that local vendored content has diverged from crate registry
#11897
Comments
Hmm… BTW, to make vendoring take effect, you need to put some configs under [source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor" |
This is a reproducer that verifies Cargo is aware of vendored source being modified:
You'll get an error like
The things you bumped into might be #9455, which registry sources are not readonly. I believe this is not I am going to close due to lack of a minimal set of steps to reproduce, and it doesn't look like an issue of cargo-vendor. Here are tips about how to create a minimal, complete, and verifiable example. Let us know if there is any update on your side. |
Hi @weihanglo. Thanks for the minimal example! Here is a tweaked version which shows the bug we intended to report: Here is an example:
So far so good -- I don't think anybody expects cargo to be able to locally detect tampering when you've updated the checksum file. Within a CI setup that has no Internet access this would be literaly impossible (absent some sort of WoT rooted inside of cargo itself I guess.) This bug report is about the following behavior though:
If you do exactly the same steps but without |
Nice catch, and thanks for the repro! The quickest fix is removing these lines. Cargo assumes that vendor sources never changes, but you never know what users would do. diff --git a/src/cargo/ops/vendor.rs b/src/cargo/ops/vendor.rs
index 3ee46db32..a9d32dc02 100644
--- a/src/cargo/ops/vendor.rs
+++ b/src/cargo/ops/vendor.rs
@@ -212,10 +212,6 @@ fn sync(
let dst = canonical_destination.join(&dst_name);
to_remove.remove(&dst);
let cksum = dst.join(".cargo-checksum.json");
- if dir_has_version_suffix && cksum.exists() {
- // Always re-copy directory without version suffix in case the version changed
- continue;
- }
config.shell().status(
"Vendoring", Given people shouldn't modify the content in the first place, I am not sure if this is a good way to resolve this. Maybe, when cargo vendors stuff, it should mark all files as read-only. Though it will lead us to #9455 I guess. |
cargo vendor
doesn't notice that local vendored content has diverged from crate registrycargo vendor --versioned-dirs
doesn't notice that local vendored content has diverged from crate registry
fix(vendor): trust crate version only when coming from registries ### What does this PR try to resolve? Fixes #8181 Relates to #11897 and #14525 ### How should we test and review this PR? As mentioned in the contribution guide, I made a first commit adding a test that passes with the actual behaviour. Then, I made a second commit with a fix and modified the test with the new expected behaviour. ### Additional information The fix doesn't take into account switching from a git dependency to crates.io, which is not handled correctly on master either, and would probably require the vendoring to serialize the source ID to detect source changes. I specifically limited the trust of immutable version to crates.io, but it could be extended to other registries.
fix(vendor): trust crate version only when coming from registries ### What does this PR try to resolve? Fixes #8181 Relates to #11897 and #14525 ### How should we test and review this PR? As mentioned in the contribution guide, I made a first commit adding a test that passes with the actual behaviour. Then, I made a second commit with a fix and modified the test with the new expected behaviour. ### Additional information The fix doesn't take into account switching from a git dependency to crates.io, which is not handled correctly on master either, and would probably require the vendoring to serialize the source ID to detect source changes. I specifically limited the trust of immutable version to crates.io, but it could be extended to other registries.
Problem
I had been hoping that I could use
cargo vendor
to quickly identify any unofficial/local changes to a crate.To test this, I made an innocuous change to a local copy of a crate -- I was expecting when I did
cargo vendor
that it would either point out the difference (or even just silently overwrite it). However, it doesn't seem to do either.The workaround seems to be to delete the entire
vendor
directory and then compare the result to what had been checked in (a lagit diff --exit-code
) -- after ignoring any semi-ephemeral content (e.g.,git add $(find . -type f -name Cargo.lock -o -name .cargo-checksum.json)
)Steps
No response
Possible Solution(s)
It's not clear to me whether this is the intended behavior for
cargo vendor
or not -- but if it is, there should be a major note on the man page aboutcargo vendor
retaining local changes.Notes
No response
Version
The text was updated successfully, but these errors were encountered: