Skip to content

Commit 9e9ac16

Browse files
committed
fix(package): all tar entries timestamp be the same
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.
1 parent 6f40a3e commit 9e9ac16

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
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: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,18 +3171,7 @@ fn reproducible_output() {
31713171
println!("checking {:?}", ent.path());
31723172
let header = ent.header();
31733173
assert_eq!(header.mode().unwrap(), 0o644);
3174-
assert!(header.mtime().unwrap() != 0);
3175-
// Generated files do not have deterministic timestamp (yet).
3176-
let path = ent.path().unwrap();
3177-
let file_name = path.file_name().unwrap().to_str().unwrap();
3178-
if ["Cargo.toml", "Cargo.lock", ".cargo_vcs_info.json"]
3179-
.into_iter()
3180-
.any(|f| f == file_name)
3181-
{
3182-
assert!(header.mtime().unwrap() != DETERMINISTIC_TIMESTAMP);
3183-
} else {
3184-
assert!(header.mtime().unwrap() == DETERMINISTIC_TIMESTAMP);
3185-
}
3174+
assert!(header.mtime().unwrap() == DETERMINISTIC_TIMESTAMP);
31863175
assert_eq!(header.username().unwrap().unwrap(), "");
31873176
assert_eq!(header.groupname().unwrap().unwrap(), "");
31883177
}

0 commit comments

Comments
 (0)