Skip to content

Commit bc0466c

Browse files
author
Andrew Leonard
committed
8279182: MakeZipReproducible ZipEntry timestamps not localized to UTC
Reviewed-by: erikj
1 parent 558a682 commit bc0466c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

make/jdk/src/classes/build/tools/makezipreproducible/MakeZipReproducible.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@
3434
import java.util.zip.ZipFile;
3535
import java.util.zip.ZipInputStream;
3636
import java.util.zip.ZipOutputStream;
37+
import java.time.Instant;
38+
import java.time.ZoneOffset;
39+
import java.time.LocalDateTime;
3740

3841
/**
3942
* Generate a zip file in a "reproducible" manner from the input zip file.
4043
* Standard zip tools rely on OS file list querying whose ordering can vary
4144
* 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.
4347
*/
4448
public class MakeZipReproducible {
4549
String input_file = null;
4650
String fname = null;
4751
String zname = "";
48-
long timestamp = -1L;
52+
LocalDateTime timestamp = null;
4953
boolean verbose = false;
5054

5155
// Keep a sorted Set of ZipEntrys to be processed, so that the zip is reproducible
@@ -117,7 +121,9 @@ boolean parseArgs(String args[]) {
117121
break;
118122
case 't':
119123
// 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);
121127
break;
122128
case 'v':
123129
verbose = true;
@@ -194,8 +200,8 @@ void addEntry(ZipOutputStream zos, ZipEntry entry, InputStream entryInputStream)
194200
}
195201

196202
// 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);
199205
}
200206

201207
zos.putNextEntry(entry);

0 commit comments

Comments
 (0)