Skip to content

Commit 9cc7ac6

Browse files
committed
package: use a consistent timestamp
For each entry in the tar archive, we generate a new timestamp. Normally cargo will be fast enough that we get a consistent timestamp, but that need not be the case. There's very little reason to produce different timestamps for different files and it's slightly more efficient not to need to make multiple queries, so let's instead generate a single timestamp for all entries that we generate.
1 parent 2af662e commit 9cc7ac6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,13 @@ fn check_repo_state(
472472
}
473473
}
474474

475+
fn timestamp() -> u64 {
476+
SystemTime::now()
477+
.duration_since(SystemTime::UNIX_EPOCH)
478+
.unwrap()
479+
.as_secs()
480+
}
481+
475482
fn tar(
476483
ws: &Workspace<'_>,
477484
ar_files: Vec<ArchiveFile>,
@@ -491,6 +498,7 @@ fn tar(
491498

492499
let base_name = format!("{}-{}", pkg.name(), pkg.version());
493500
let base_path = Path::new(&base_name);
501+
let time = timestamp();
494502
for ar_file in ar_files {
495503
let ArchiveFile {
496504
rel_path,
@@ -525,12 +533,7 @@ fn tar(
525533
};
526534
header.set_entry_type(EntryType::file());
527535
header.set_mode(0o644);
528-
header.set_mtime(
529-
SystemTime::now()
530-
.duration_since(SystemTime::UNIX_EPOCH)
531-
.unwrap()
532-
.as_secs(),
533-
);
536+
header.set_mtime(time);
534537
header.set_size(contents.len() as u64);
535538
header.set_cksum();
536539
ar.append_data(&mut header, &ar_path, contents.as_bytes())

0 commit comments

Comments
 (0)