@@ -32,6 +32,12 @@ actor! {
32
32
/// The formats used to compress the tarball.
33
33
#[ arg( value_name = "FORMAT" , default_value_t) ]
34
34
compression_formats: CompressionFormats ,
35
+
36
+ /// Modification time that will be set for all files added to the archive.
37
+ /// The default is the date of the first Rust commit from 2006.
38
+ /// This serves for better reproducibility of the archives.
39
+ #[ arg( value_name = "FILE_MTIME" , default_value_t = 1153704088 ) ]
40
+ override_file_mtime: u64 ,
35
41
}
36
42
}
37
43
@@ -65,6 +71,8 @@ impl Tarballer {
65
71
let buf = BufWriter :: with_capacity ( 1024 * 1024 , encoder) ;
66
72
let mut builder = Builder :: new ( buf) ;
67
73
// Make uid, gid and mtime deterministic to improve reproducibility
74
+ // The modification time of directories will be set to the date of the first Rust commit.
75
+ // The modification time of files will be set to `override_file_mtime` (see `append_path`).
68
76
builder. mode ( HeaderMode :: Deterministic ) ;
69
77
70
78
let pool = rayon:: ThreadPoolBuilder :: new ( ) . num_threads ( 2 ) . build ( ) . unwrap ( ) ;
@@ -77,7 +85,7 @@ impl Tarballer {
77
85
}
78
86
for path in files {
79
87
let src = Path :: new ( & self . work_dir ) . join ( & path) ;
80
- append_path ( & mut builder, & src, & path)
88
+ append_path ( & mut builder, & src, & path, self . override_file_mtime )
81
89
. with_context ( || format ! ( "failed to tar file '{}'" , src. display( ) ) ) ?;
82
90
}
83
91
builder
@@ -93,10 +101,16 @@ impl Tarballer {
93
101
}
94
102
}
95
103
96
- fn append_path < W : Write > ( builder : & mut Builder < W > , src : & Path , path : & String ) -> Result < ( ) > {
104
+ fn append_path < W : Write > (
105
+ builder : & mut Builder < W > ,
106
+ src : & Path ,
107
+ path : & String ,
108
+ override_file_mtime : u64 ,
109
+ ) -> Result < ( ) > {
97
110
let stat = symlink_metadata ( src) ?;
98
111
let mut header = Header :: new_gnu ( ) ;
99
112
header. set_metadata_in_mode ( & stat, HeaderMode :: Deterministic ) ;
113
+ header. set_mtime ( override_file_mtime) ;
100
114
101
115
if stat. file_type ( ) . is_symlink ( ) {
102
116
let link = read_link ( src) ?;
0 commit comments