From 18d9d44bd6f431db4e50f5636b08458a8a1a63c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 30 Mar 2024 21:27:58 +0100 Subject: [PATCH] Make tarball generation more deterministic --- src/tools/rust-installer/src/tarballer.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tools/rust-installer/src/tarballer.rs b/src/tools/rust-installer/src/tarballer.rs index e5a925b2cbf..24d341db78e 100644 --- a/src/tools/rust-installer/src/tarballer.rs +++ b/src/tools/rust-installer/src/tarballer.rs @@ -2,7 +2,7 @@ use std::fs::{read_link, symlink_metadata}; use std::io::{BufWriter, Write}; use std::path::Path; -use tar::{Builder, Header}; +use tar::{Builder, Header, HeaderMode}; use walkdir::WalkDir; use crate::{ @@ -61,6 +61,8 @@ pub fn run(self) -> Result<()> { // first, so files may be directly created. (See rust-lang/rustup.rs#1092.) let buf = BufWriter::with_capacity(1024 * 1024, encoder); let mut builder = Builder::new(buf); + // Make uid, gid and mtime deterministic to improve reproducibility + builder.mode(HeaderMode::Deterministic); let pool = rayon::ThreadPoolBuilder::new().num_threads(2).build().unwrap(); pool.install(move || { @@ -91,7 +93,8 @@ pub fn run(self) -> Result<()> { fn append_path(builder: &mut Builder, src: &Path, path: &String) -> Result<()> { let stat = symlink_metadata(src)?; let mut header = Header::new_gnu(); - header.set_metadata(&stat); + header.set_metadata_in_mode(&stat, HeaderMode::Deterministic); + if stat.file_type().is_symlink() { let link = read_link(src)?; builder.append_link(&mut header, path, &link)?;