011-add-option-for-reproducible-archives.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. From 6d659fc87451c02c8777dc33f750b16834e4c715 Mon Sep 17 00:00:00 2001
  2. From: Mathias Kresin <dev@kresin.me>
  3. Date: Sat, 12 Jan 2019 19:33:33 +0100
  4. Subject: [PATCH] add option for reproducible archives
  5. Add the option -mt/--mtime to pass a timestamp which is used as filedate
  6. for the containing files.
  7. So far, it isn't used for anything written to the extra fields,
  8. therefore requires the -X (eXclude eXtra file attributes) parameter to
  9. be effective.
  10. Signed-off-by: Mathias Kresin <dev@kresin.me>
  11. ---
  12. globals.c | 1 +
  13. util.c | 22 ++++++++++++++++++++++
  14. zip.c | 6 ++++++
  15. zip.h | 1 +
  16. zipup.c | 4 +++-
  17. 5 files changed, 33 insertions(+), 1 deletion(-)
  18. --- a/globals.c
  19. +++ b/globals.c
  20. @@ -205,6 +205,7 @@ uzoff_t bytes_this_split = 0; /* byt
  21. int read_split_archive = 0; /* 1=scanzipf_reg detected spanning signature */
  22. int split_method = 0; /* 0=no splits, 1=seekable, 2=data desc, -1=no */
  23. uzoff_t split_size = 0; /* how big each split should be */
  24. +time_t timestamp = -1; /* fixed timestamp for archive content filedate */
  25. int split_bell = 0; /* when pause for next split ring bell */
  26. uzoff_t bytes_prev_splits = 0; /* total bytes written to all splits before this */
  27. uzoff_t bytes_this_entry = 0; /* bytes written for this entry across all splits */
  28. --- a/util.c
  29. +++ b/util.c
  30. @@ -1217,6 +1217,7 @@ int DisplayNumString(file, i)
  31. return 0;
  32. }
  33. +
  34. /* Read numbers with trailing size multiplier (like 10M) and return number.
  35. 10/30/04 EG */
  36. @@ -1279,6 +1280,29 @@ uzoff_t ReadNumString( numstring )
  37. }
  38. +uzoff_t ReadNumStringUL( numstring )
  39. + char *numstring;
  40. +{
  41. + zoff_t num = 0;
  42. +
  43. + /* check if valid number (currently no negatives) */
  44. + if (numstring == NULL) {
  45. + zipwarn("Unable to read empty number in ReadNumString", "");
  46. + return (uzoff_t)-1;
  47. + }
  48. + if (numstring[0] < '0' || numstring[0] > '9') {
  49. + zipwarn("Unable to read number (must start with digit): ", numstring);
  50. + return (uzoff_t)-1;
  51. + }
  52. + if (strlen(numstring) > 10) {
  53. + zipwarn("Number too long to read (10 characters max): ", numstring);
  54. + return (uzoff_t)-1;
  55. + }
  56. +
  57. + return (uzoff_t)atoll(numstring);
  58. +}
  59. +
  60. +
  61. /* Write the number as a string with a multiplier (like 10M) to outstring.
  62. Always writes no more than 3 digits followed maybe by a multiplier and
  63. returns the characters written or -1 if error.
  64. --- a/zip.c
  65. +++ b/zip.c
  66. @@ -1942,6 +1942,7 @@ int set_filetype(out_path)
  67. #ifdef UNICODE_TEST
  68. #define o_sC 0x146
  69. #endif
  70. +#define o_mt 0x255
  71. /* the below is mainly from the old main command line
  72. @@ -2036,6 +2037,7 @@ struct option_struct far options[] = {
  73. {"m", "move", o_NO_VALUE, o_NOT_NEGATABLE, 'm', "add files to archive then delete files"},
  74. {"mm", "", o_NO_VALUE, o_NOT_NEGATABLE, o_mm, "not used"},
  75. {"MM", "must-match", o_NO_VALUE, o_NOT_NEGATABLE, o_MM, "error if in file not matched/not readable"},
  76. + {"mt", "mtime", o_REQUIRED_VALUE, o_NOT_NEGATABLE, o_mt, "use fixed timestamp for archive content filedate"},
  77. {"n", "suffixes", o_REQUIRED_VALUE, o_NOT_NEGATABLE, 'n', "suffixes to not compress: .gz:.zip"},
  78. {"nw", "no-wild", o_NO_VALUE, o_NOT_NEGATABLE, o_nw, "no wildcards during add or update"},
  79. #if defined(AMIGA) || defined(MACOS)
  80. @@ -2440,6 +2442,7 @@ char **argv; /* command line
  81. split_method = 0; /* 0=no splits, 1=update LHs, 2=data descriptors */
  82. split_size = 0; /* how big each split should be */
  83. split_bell = 0; /* when pause for next split ring bell */
  84. + timestamp = -1; /* fixed timestamp for archive content filedate */
  85. bytes_prev_splits = 0; /* total bytes written to all splits before this */
  86. bytes_this_entry = 0; /* bytes written for this entry across all splits */
  87. noisy_splits = 0; /* be verbose about creating splits */
  88. @@ -2897,6 +2900,9 @@ char **argv; /* command line
  89. dispose = 1; break;
  90. case o_MM: /* Exit with error if input file can't be read */
  91. bad_open_is_error = 1; break;
  92. + case o_mt: /* fixed timestamp for archive content filedate */
  93. + timestamp = ReadNumStringUL(value);
  94. + break;
  95. case 'n': /* Don't compress files with a special suffix */
  96. special = value;
  97. /* special = NULL; */ /* will be set at next argument */
  98. --- a/zip.h
  99. +++ b/zip.h
  100. @@ -502,6 +502,7 @@ extern uzoff_t bytes_this_split; /* byte
  101. extern int read_split_archive; /* 1=scanzipf_reg detected spanning signature */
  102. extern int split_method; /* 0=no splits, 1=seekable, 2=data descs, -1=no */
  103. extern uzoff_t split_size; /* how big each split should be */
  104. +extern time_t timestamp; /* fixed timestamp for archive content filedate */
  105. extern int split_bell; /* when pause for next split ring bell */
  106. extern uzoff_t bytes_prev_splits; /* total bytes written to all splits before this */
  107. extern uzoff_t bytes_this_entry; /* bytes written for this entry across all splits */
  108. @@ -789,6 +790,7 @@ char *zip_fzofft OF((zoff_t, char
  109. int DisplayNumString OF ((FILE *file, uzoff_t i));
  110. int WriteNumString OF((uzoff_t num, char *outstring));
  111. uzoff_t ReadNumString OF((char *numstring));
  112. +uzoff_t ReadNumStringUL OF((char *numstring));
  113. /* returns true if abbrev is abbreviation for string */
  114. int abbrevmatch OF((char *, char *, int, int));
  115. --- a/zipup.c
  116. +++ b/zipup.c
  117. @@ -415,7 +415,6 @@ struct zlist far *z; /* zip entry to
  118. char *tempextra = NULL;
  119. char *tempcextra = NULL;
  120. -
  121. #ifdef WINDLL
  122. # ifdef ZIP64_SUPPORT
  123. extern _int64 filesize64;
  124. @@ -441,6 +440,9 @@ struct zlist far *z; /* zip entry to
  125. if (tim == 0 || q == (zoff_t) -3)
  126. return ZE_OPEN;
  127. + if (timestamp > 0)
  128. + tim = unix2dostime(&timestamp);
  129. +
  130. /* q is set to -1 if the input file is a device, -2 for a volume label */
  131. if (q == (zoff_t) -2) {
  132. isdir = 1;