Skip to content

Commit

Permalink
Make tarball generation more deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Mar 30, 2024
1 parent dfd24b5 commit 45c3662
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tools/rust-installer/src/tarballer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{bail, Context, Result};
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::{
Expand Down Expand Up @@ -61,6 +61,8 @@ impl Tarballer {
// 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 || {
Expand Down Expand Up @@ -91,7 +93,8 @@ impl Tarballer {
fn append_path<W: Write>(builder: &mut Builder<W>, 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)?;
Expand Down

0 comments on commit 45c3662

Please sign in to comment.