Skip to content
Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bmwiedemann committed May 3, 2019
1 parent e158676 commit 501ae4e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions zipup.c
Expand Up @@ -414,6 +414,7 @@ struct zlist far *z; /* zip entry to compress */
ush tempcext = 0;
char *tempextra = NULL;
char *tempcextra = NULL;
const char *source_date_epoch;


#ifdef WINDLL
Expand Down Expand Up @@ -674,6 +675,13 @@ struct zlist far *z; /* zip entry to compress */

} /* 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;
Expand Down

0 comments on commit 501ae4e

Please sign in to comment.