011-reproducible-mtime.patch 1.2 KB

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