Skip to content

Commit e7246c6

Browse files
authored
fix(package): all tar entries timestamp be the same (#16242)
### What does this PR try to resolve? With this commit, all tar entries' timestamp is the same, all set to DETERMINISTIC_TIMESTAMP in tar-rs. This fixes the first half of #16237 that `cargo package` should tar everything in the same timestamp. ### How to test and review this PR? Test passes.
2 parents 4b0e263 + 9e9ac16 commit e7246c6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,12 @@ fn tar(
917917
header.set_entry_type(EntryType::file());
918918
header.set_mode(0o644);
919919
header.set_size(contents.len() as u64);
920-
// use something nonzero to avoid rust-lang/cargo#9512
921-
header.set_mtime(1);
920+
// We need to have the same DETERMINISTIC_TIMESTAMP for generated files
921+
// https://github.com/alexcrichton/tar-rs/blob/d0261f1f6cc959ba0758e7236b3fd81e90dd1dc6/src/header.rs#L18-L24
922+
// Unfortunately tar-rs doesn't expose that so we harcode the timestamp here.
923+
// Hardcoded value be removed once alexcrichton/tar-rs#420 is merged and released.
924+
// See also rust-lang/cargo#16237
925+
header.set_mtime(1153704088);
922926
header.set_cksum();
923927
ar.append_data(&mut header, &ar_path, contents.as_bytes())
924928
.with_context(|| format!("could not archive source file `{}`", rel_str))?;

tests/testsuite/package.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3162,12 +3162,16 @@ fn reproducible_output() {
31623162
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
31633163
let decoder = GzDecoder::new(f);
31643164
let mut archive = Archive::new(decoder);
3165+
3166+
// Hardcoded value be removed once alexcrichton/tar-rs#420 is merged and released.
3167+
// See also rust-lang/cargo#16237
3168+
const DETERMINISTIC_TIMESTAMP: u64 = 1153704088;
31653169
for ent in archive.entries().unwrap() {
31663170
let ent = ent.unwrap();
31673171
println!("checking {:?}", ent.path());
31683172
let header = ent.header();
31693173
assert_eq!(header.mode().unwrap(), 0o644);
3170-
assert!(header.mtime().unwrap() != 0);
3174+
assert!(header.mtime().unwrap() == DETERMINISTIC_TIMESTAMP);
31713175
assert_eq!(header.username().unwrap().unwrap(), "");
31723176
assert_eq!(header.groupname().unwrap().unwrap(), "");
31733177
}

0 commit comments

Comments
 (0)