|
34 | 34 | import java.util.zip.ZipFile; |
35 | 35 | import java.util.zip.ZipInputStream; |
36 | 36 | import java.util.zip.ZipOutputStream; |
| 37 | +import java.time.Instant; |
| 38 | +import java.time.ZoneOffset; |
| 39 | +import java.time.LocalDateTime; |
37 | 40 |
|
38 | 41 | /** |
39 | 42 | * Generate a zip file in a "reproducible" manner from the input zip file. |
40 | 43 | * Standard zip tools rely on OS file list querying whose ordering can vary |
41 | 44 | * by platform architecture, this class ensures the zip entries are ordered |
42 | | - * and also supports SOURCE_DATE_EPOCH timestamps. |
| 45 | + * and also supports SOURCE_DATE_EPOCH timestamps which will set the ZipEntry |
| 46 | + * local time in UTC. |
43 | 47 | */ |
44 | 48 | public class MakeZipReproducible { |
45 | 49 | String input_file = null; |
46 | 50 | String fname = null; |
47 | 51 | String zname = ""; |
48 | | - long timestamp = -1L; |
| 52 | + LocalDateTime timestamp = null; |
49 | 53 | boolean verbose = false; |
50 | 54 |
|
51 | 55 | // Keep a sorted Set of ZipEntrys to be processed, so that the zip is reproducible |
@@ -117,7 +121,9 @@ boolean parseArgs(String args[]) { |
117 | 121 | break; |
118 | 122 | case 't': |
119 | 123 | // SOURCE_DATE_EPOCH timestamp specified |
120 | | - timestamp = Long.parseLong(args[++count]) * 1000; |
| 124 | + long epochSeconds = Long.parseLong(args[++count]); |
| 125 | + Instant instant = Instant.ofEpochSecond(epochSeconds); |
| 126 | + timestamp = LocalDateTime.ofInstant(instant, ZoneOffset.UTC); |
121 | 127 | break; |
122 | 128 | case 'v': |
123 | 129 | verbose = true; |
@@ -194,8 +200,8 @@ void addEntry(ZipOutputStream zos, ZipEntry entry, InputStream entryInputStream) |
194 | 200 | } |
195 | 201 |
|
196 | 202 | // Set to specified timestamp if set otherwise leave as original lastModified time |
197 | | - if (timestamp != -1L) { |
198 | | - entry.setTime(timestamp); |
| 203 | + if (timestamp != null) { |
| 204 | + entry.setTimeLocal(timestamp); |
199 | 205 | } |
200 | 206 |
|
201 | 207 | zos.putNextEntry(entry); |
|
0 commit comments