tools: zip: fetch SOURCE_DATE_EPOCH directly
[openwrt/openwrt.git] / tools / zip / patches / 011-reproducible-mtime.patch
1 From 501ae4e93fd6fa2f7d20d00d1b011f9006802eae Mon Sep 17 00:00:00 2001
2 From: "Bernhard M. Wiedemann" <bwiedemann@suse.de>
3 Date: Fri, 3 May 2019 16:32:24 +0200
4 Subject: [PATCH] Override mtime with zip -X
5
6 with SOURCE_DATE_EPOCH
7 to allow for reproducible builds of .zip files
8
9 See https://reproducible-builds.org/ for why this is good
10 and https://reproducible-builds.org/specs/source-date-epoch/
11 for the definition of this variable.
12
13 Uses clamping to keep older mtimes than SOURCE_DATE_EPOCH intact.
14 ---
15 zipup.c | 8 ++++++++
16 1 file changed, 8 insertions(+)
17
18 --- a/zipup.c
19 +++ b/zipup.c
20 @@ -414,6 +414,7 @@ struct zlist far *z; /* zip entry to
21 ush tempcext = 0;
22 char *tempextra = NULL;
23 char *tempcextra = NULL;
24 + const char *source_date_epoch;
25
26
27 #ifdef WINDLL
28 @@ -674,6 +675,13 @@ struct zlist far *z; /* zip entry to
29
30 } /* strcmp(z->name, "-") == 0 */
31
32 + if (extra_fields == 0 && (source_date_epoch = getenv("SOURCE_DATE_EPOCH")) != NULL) {
33 + time_t epoch = strtoull(source_date_epoch, NULL, 10);
34 + if (epoch > 0) {
35 + ulg epochtim = unix2dostime(&epoch);
36 + if (z->tim > epochtim) z->tim = epochtim;
37 + }
38 + }
39 if (extra_fields == 2) {
40 unsigned len;
41 char *p;