Add missing truncate when writing .crate files#16688
Add missing truncate when writing .crate files#16688weihanglo merged 4 commits intorust-lang:masterfrom
Conversation
|
r? @epage rustbot has assigned @epage. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
Thanks for the fix. Would you mind adding a test for it?
For bugfixes, we usually follow a variant of atomic commit pattern:
- Commit a test that asserts the current buggy behavior (passes).
- In the next commit, fix the bug and update the test/snapshot.
Every commit passes, and the test/snapshot diff shows the behavior change.
|
Should we consider backporting this to beta (now 1.95)? Looks like this was introduced in 1.93. |
Agreed. Thanks for pointing this out. @rustbot label +beta-nominated |
8181b1e to
ff45d84
Compare
There was a problem hiding this comment.
Thanks!
I believe the temp registry has the same issue. Could you please fix it as well?
This case cloud help us catch the bug:
#[cargo_test]
fn repackage_smaller_local_dep_tmp_registry_checksum_match() {
let reg = registry::init();
let big_file_contents = "x".repeat(100_000);
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar"]
resolver = "2"
"#,
)
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2021"
[dependencies]
bar = { path = "../bar", version = "0.0.1" }
"#,
)
.file("foo/src/lib.rs", "pub fn foo() { bar::bar(); }")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
edition = "2021"
include = ["src/**", "Cargo.toml", "big.txt"]
"#,
)
.file("bar/src/lib.rs", "pub fn bar() {}")
.file("bar/big.txt", &big_file_contents)
.build();
p.cargo("package --workspace --no-verify")
.replace_crates_io(reg.index_url())
.run();
fs::remove_file(p.root().join("bar/big.txt")).unwrap();
p.change_file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
edition = "2021"
include = ["src/**", "Cargo.toml"]
"#,
);
p.cargo("package --workspace --no-verify")
.replace_crates_io(reg.index_url())
.run();
let index_line = read_to_string(p.root().join("target/package/tmp-registry/index/3/b/bar"))
.unwrap()
.lines()
.last()
.unwrap()
.to_owned();
let expected_cksum = serde_json::from_str::<serde_json::Value>(&index_line)
.unwrap()
.get("cksum")
.and_then(|value| value.as_str())
.unwrap()
.to_owned();
let crate_contents = fs::read(p.root().join("target/package/tmp-registry/bar-0.0.1.crate"))
.unwrap();
let actual_cksum = registry::cksum(&crate_contents);
assert_eq!(
expected_cksum, actual_cksum,
"tmp-registry crate checksum should match index entry"
);
p.cargo("package --workspace")
.replace_crates_io(reg.index_url())
.run();
}I would suggest that when adding the test, the Conventional Commit Message should start with test: instead of add: .
|
Reminder, once the PR becomes ready for a review, use |
ff45d84 to
76d432f
Compare
|
Well, seems irrelavent with my code. @rustbot ready |
PR author has made the test and change.
<!-- _Thanks for the pull request 🎉!_ _Please read the contribution guide: <https://doc.crates.io/contrib/>._ --> ### What does this PR try to resolve? Fixes rust-lang#16683 by adding manuall truncate. <!-- _Explain the motivation behind this change._ _A clear overview along with an in-depth explanation are helpful._ --> ### How to test and review this PR? See the original issue for mCVE. <!-- _Demonstrate how you test this change and guide reviewers through your PR._ _With a smooth review process, a pull request usually gets reviewed quicker._ -->
<!-- _Thanks for the pull request 🎉!_ _Please read the contribution guide: <https://doc.crates.io/contrib/>._ --> ### What does this PR try to resolve? Fixes rust-lang#16683 by adding manuall truncate. <!-- _Explain the motivation behind this change._ _A clear overview along with an in-depth explanation are helpful._ --> ### How to test and review this PR? See the original issue for mCVE. <!-- _Demonstrate how you test this change and guide reviewers through your PR._ _With a smooth review process, a pull request usually gets reviewed quicker._ -->
Beta backports - #16688 In order to make CI pass, the following PRs are also cherry-picked: -
What does this PR try to resolve?
Fixes #16683 by adding manuall truncate.
How to test and review this PR?
See the original issue for mCVE.