tools: zip: fetch SOURCE_DATE_EPOCH directly
Remove "--mtime" option introduced in commit 18c9faa032
("tools: zip:
add option for reproducible archives") and instead fetch SOURCE_DATE_EPOCH
environment variable directly in the code.
Ref: https://sourceforge.net/p/infozip/patches/25/
Signed-off-by: Sungbo Eo <mans0n@gorani.run>
This commit is contained in:
parent
e42764cc5f
commit
39d06472eb
@ -542,7 +542,6 @@ define Build/zip
|
||||
mkdir $@.tmp
|
||||
mv $@ $@.tmp/$(word 1,$(1))
|
||||
TZ=UTC $(STAGING_DIR_HOST)/bin/zip -j -X \
|
||||
$(if $(SOURCE_DATE_EPOCH),--mtime="$(SOURCE_DATE_EPOCH)") \
|
||||
$(wordlist 2,$(words $(1)),$(1)) \
|
||||
$@ $@.tmp/$(if $(word 1,$(1)),$(word 1,$(1)),$$(basename $@))
|
||||
rm -rf $@.tmp
|
||||
|
@ -1,145 +0,0 @@
|
||||
From 6d659fc87451c02c8777dc33f750b16834e4c715 Mon Sep 17 00:00:00 2001
|
||||
From: Mathias Kresin <dev@kresin.me>
|
||||
Date: Sat, 12 Jan 2019 19:33:33 +0100
|
||||
Subject: [PATCH] add option for reproducible archives
|
||||
|
||||
Add the option -mt/--mtime to pass a timestamp which is used as filedate
|
||||
for the containing files.
|
||||
|
||||
So far, it isn't used for anything written to the extra fields,
|
||||
therefore requires the -X (eXclude eXtra file attributes) parameter to
|
||||
be effective.
|
||||
|
||||
Signed-off-by: Mathias Kresin <dev@kresin.me>
|
||||
---
|
||||
globals.c | 1 +
|
||||
util.c | 22 ++++++++++++++++++++++
|
||||
zip.c | 6 ++++++
|
||||
zip.h | 1 +
|
||||
zipup.c | 4 +++-
|
||||
5 files changed, 33 insertions(+), 1 deletion(-)
|
||||
|
||||
--- a/globals.c
|
||||
+++ b/globals.c
|
||||
@@ -205,6 +205,7 @@ uzoff_t bytes_this_split = 0; /* byt
|
||||
int read_split_archive = 0; /* 1=scanzipf_reg detected spanning signature */
|
||||
int split_method = 0; /* 0=no splits, 1=seekable, 2=data desc, -1=no */
|
||||
uzoff_t split_size = 0; /* how big each split should be */
|
||||
+time_t timestamp = -1; /* fixed timestamp for archive content filedate */
|
||||
int split_bell = 0; /* when pause for next split ring bell */
|
||||
uzoff_t bytes_prev_splits = 0; /* total bytes written to all splits before this */
|
||||
uzoff_t bytes_this_entry = 0; /* bytes written for this entry across all splits */
|
||||
--- a/util.c
|
||||
+++ b/util.c
|
||||
@@ -1217,6 +1217,7 @@ int DisplayNumString(file, i)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+
|
||||
/* Read numbers with trailing size multiplier (like 10M) and return number.
|
||||
10/30/04 EG */
|
||||
|
||||
@@ -1279,6 +1280,29 @@ uzoff_t ReadNumString( numstring )
|
||||
}
|
||||
|
||||
|
||||
+uzoff_t ReadNumStringUL( numstring )
|
||||
+ char *numstring;
|
||||
+{
|
||||
+ zoff_t num = 0;
|
||||
+
|
||||
+ /* check if valid number (currently no negatives) */
|
||||
+ if (numstring == NULL) {
|
||||
+ zipwarn("Unable to read empty number in ReadNumString", "");
|
||||
+ return (uzoff_t)-1;
|
||||
+ }
|
||||
+ if (numstring[0] < '0' || numstring[0] > '9') {
|
||||
+ zipwarn("Unable to read number (must start with digit): ", numstring);
|
||||
+ return (uzoff_t)-1;
|
||||
+ }
|
||||
+ if (strlen(numstring) > 10) {
|
||||
+ zipwarn("Number too long to read (10 characters max): ", numstring);
|
||||
+ return (uzoff_t)-1;
|
||||
+ }
|
||||
+
|
||||
+ return (uzoff_t)atoll(numstring);
|
||||
+}
|
||||
+
|
||||
+
|
||||
/* Write the number as a string with a multiplier (like 10M) to outstring.
|
||||
Always writes no more than 3 digits followed maybe by a multiplier and
|
||||
returns the characters written or -1 if error.
|
||||
--- a/zip.c
|
||||
+++ b/zip.c
|
||||
@@ -1942,6 +1942,7 @@ int set_filetype(out_path)
|
||||
#ifdef UNICODE_TEST
|
||||
#define o_sC 0x146
|
||||
#endif
|
||||
+#define o_mt 0x255
|
||||
|
||||
|
||||
/* the below is mainly from the old main command line
|
||||
@@ -2036,6 +2037,7 @@ struct option_struct far options[] = {
|
||||
{"m", "move", o_NO_VALUE, o_NOT_NEGATABLE, 'm', "add files to archive then delete files"},
|
||||
{"mm", "", o_NO_VALUE, o_NOT_NEGATABLE, o_mm, "not used"},
|
||||
{"MM", "must-match", o_NO_VALUE, o_NOT_NEGATABLE, o_MM, "error if in file not matched/not readable"},
|
||||
+ {"mt", "mtime", o_REQUIRED_VALUE, o_NOT_NEGATABLE, o_mt, "use fixed timestamp for archive content filedate"},
|
||||
{"n", "suffixes", o_REQUIRED_VALUE, o_NOT_NEGATABLE, 'n', "suffixes to not compress: .gz:.zip"},
|
||||
{"nw", "no-wild", o_NO_VALUE, o_NOT_NEGATABLE, o_nw, "no wildcards during add or update"},
|
||||
#if defined(AMIGA) || defined(MACOS)
|
||||
@@ -2440,6 +2442,7 @@ char **argv; /* command line
|
||||
split_method = 0; /* 0=no splits, 1=update LHs, 2=data descriptors */
|
||||
split_size = 0; /* how big each split should be */
|
||||
split_bell = 0; /* when pause for next split ring bell */
|
||||
+ timestamp = -1; /* fixed timestamp for archive content filedate */
|
||||
bytes_prev_splits = 0; /* total bytes written to all splits before this */
|
||||
bytes_this_entry = 0; /* bytes written for this entry across all splits */
|
||||
noisy_splits = 0; /* be verbose about creating splits */
|
||||
@@ -2897,6 +2900,9 @@ char **argv; /* command line
|
||||
dispose = 1; break;
|
||||
case o_MM: /* Exit with error if input file can't be read */
|
||||
bad_open_is_error = 1; break;
|
||||
+ case o_mt: /* fixed timestamp for archive content filedate */
|
||||
+ timestamp = ReadNumStringUL(value);
|
||||
+ break;
|
||||
case 'n': /* Don't compress files with a special suffix */
|
||||
special = value;
|
||||
/* special = NULL; */ /* will be set at next argument */
|
||||
--- a/zip.h
|
||||
+++ b/zip.h
|
||||
@@ -502,6 +502,7 @@ extern uzoff_t bytes_this_split; /* byte
|
||||
extern int read_split_archive; /* 1=scanzipf_reg detected spanning signature */
|
||||
extern int split_method; /* 0=no splits, 1=seekable, 2=data descs, -1=no */
|
||||
extern uzoff_t split_size; /* how big each split should be */
|
||||
+extern time_t timestamp; /* fixed timestamp for archive content filedate */
|
||||
extern int split_bell; /* when pause for next split ring bell */
|
||||
extern uzoff_t bytes_prev_splits; /* total bytes written to all splits before this */
|
||||
extern uzoff_t bytes_this_entry; /* bytes written for this entry across all splits */
|
||||
@@ -789,6 +790,7 @@ char *zip_fzofft OF((zoff_t, char
|
||||
int DisplayNumString OF ((FILE *file, uzoff_t i));
|
||||
int WriteNumString OF((uzoff_t num, char *outstring));
|
||||
uzoff_t ReadNumString OF((char *numstring));
|
||||
+uzoff_t ReadNumStringUL OF((char *numstring));
|
||||
|
||||
/* returns true if abbrev is abbreviation for string */
|
||||
int abbrevmatch OF((char *, char *, int, int));
|
||||
--- a/zipup.c
|
||||
+++ b/zipup.c
|
||||
@@ -415,7 +415,6 @@ struct zlist far *z; /* zip entry to
|
||||
char *tempextra = NULL;
|
||||
char *tempcextra = NULL;
|
||||
|
||||
-
|
||||
#ifdef WINDLL
|
||||
# ifdef ZIP64_SUPPORT
|
||||
extern _int64 filesize64;
|
||||
@@ -441,6 +440,9 @@ struct zlist far *z; /* zip entry to
|
||||
if (tim == 0 || q == (zoff_t) -3)
|
||||
return ZE_OPEN;
|
||||
|
||||
+ if (timestamp > 0)
|
||||
+ tim = unix2dostime(×tamp);
|
||||
+
|
||||
/* q is set to -1 if the input file is a device, -2 for a volume label */
|
||||
if (q == (zoff_t) -2) {
|
||||
isdir = 1;
|
41
tools/zip/patches/011-reproducible-mtime.patch
Normal file
41
tools/zip/patches/011-reproducible-mtime.patch
Normal file
@ -0,0 +1,41 @@
|
||||
From 501ae4e93fd6fa2f7d20d00d1b011f9006802eae Mon Sep 17 00:00:00 2001
|
||||
From: "Bernhard M. Wiedemann" <bwiedemann@suse.de>
|
||||
Date: Fri, 3 May 2019 16:32:24 +0200
|
||||
Subject: [PATCH] Override mtime with zip -X
|
||||
|
||||
with SOURCE_DATE_EPOCH
|
||||
to allow for reproducible builds of .zip files
|
||||
|
||||
See https://reproducible-builds.org/ for why this is good
|
||||
and https://reproducible-builds.org/specs/source-date-epoch/
|
||||
for the definition of this variable.
|
||||
|
||||
Uses clamping to keep older mtimes than SOURCE_DATE_EPOCH intact.
|
||||
---
|
||||
zipup.c | 8 ++++++++
|
||||
1 file changed, 8 insertions(+)
|
||||
|
||||
--- a/zipup.c
|
||||
+++ b/zipup.c
|
||||
@@ -414,6 +414,7 @@ struct zlist far *z; /* zip entry to
|
||||
ush tempcext = 0;
|
||||
char *tempextra = NULL;
|
||||
char *tempcextra = NULL;
|
||||
+ const char *source_date_epoch;
|
||||
|
||||
|
||||
#ifdef WINDLL
|
||||
@@ -674,6 +675,13 @@ struct zlist far *z; /* zip entry to
|
||||
|
||||
} /* strcmp(z->name, "-") == 0 */
|
||||
|
||||
+ if (extra_fields == 0 && (source_date_epoch = getenv("SOURCE_DATE_EPOCH")) != NULL) {
|
||||
+ time_t epoch = strtoull(source_date_epoch, NULL, 10);
|
||||
+ if (epoch > 0) {
|
||||
+ ulg epochtim = unix2dostime(&epoch);
|
||||
+ if (z->tim > epochtim) z->tim = epochtim;
|
||||
+ }
|
||||
+ }
|
||||
if (extra_fields == 2) {
|
||||
unsigned len;
|
||||
char *p;
|
Loading…
Reference in New Issue
Block a user