Make tarball generation more deterministic
This commit is contained in:
parent
8caef4e6c3
commit
18d9d44bd6
@ -2,7 +2,7 @@
|
|||||||
use std::fs::{read_link, symlink_metadata};
|
use std::fs::{read_link, symlink_metadata};
|
||||||
use std::io::{BufWriter, Write};
|
use std::io::{BufWriter, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tar::{Builder, Header};
|
use tar::{Builder, Header, HeaderMode};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -61,6 +61,8 @@ pub fn run(self) -> Result<()> {
|
|||||||
// first, so files may be directly created. (See rust-lang/rustup.rs#1092.)
|
// first, so files may be directly created. (See rust-lang/rustup.rs#1092.)
|
||||||
let buf = BufWriter::with_capacity(1024 * 1024, encoder);
|
let buf = BufWriter::with_capacity(1024 * 1024, encoder);
|
||||||
let mut builder = Builder::new(buf);
|
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();
|
let pool = rayon::ThreadPoolBuilder::new().num_threads(2).build().unwrap();
|
||||||
pool.install(move || {
|
pool.install(move || {
|
||||||
@ -91,7 +93,8 @@ pub fn run(self) -> Result<()> {
|
|||||||
fn append_path<W: Write>(builder: &mut Builder<W>, src: &Path, path: &String) -> Result<()> {
|
fn append_path<W: Write>(builder: &mut Builder<W>, src: &Path, path: &String) -> Result<()> {
|
||||||
let stat = symlink_metadata(src)?;
|
let stat = symlink_metadata(src)?;
|
||||||
let mut header = Header::new_gnu();
|
let mut header = Header::new_gnu();
|
||||||
header.set_metadata(&stat);
|
header.set_metadata_in_mode(&stat, HeaderMode::Deterministic);
|
||||||
|
|
||||||
if stat.file_type().is_symlink() {
|
if stat.file_type().is_symlink() {
|
||||||
let link = read_link(src)?;
|
let link = read_link(src)?;
|
||||||
builder.append_link(&mut header, path, &link)?;
|
builder.append_link(&mut header, path, &link)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user