blob: 6ce8445e831fb9bb9ece3578ce9f39e304cc759d [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 501ae4e93fd6fa2f7d20d00d1b011f9006802eae Mon Sep 17 00:00:00 2001
2From: "Bernhard M. Wiedemann" <bwiedemann@suse.de>
3Date: Fri, 3 May 2019 16:32:24 +0200
4Subject: [PATCH] Override mtime with zip -X
5
6with SOURCE_DATE_EPOCH
7to allow for reproducible builds of .zip files
8
9See https://reproducible-builds.org/ for why this is good
10and https://reproducible-builds.org/specs/source-date-epoch/
11for the definition of this variable.
12
13Uses 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;