Navigation Menu

Skip to content


8279182: MakeZipReproducible ZipEntry timestamps not localized to UTC
Browse files Browse the repository at this point in the history
Backport-of: bc0466c7ca57f14b1e6285e2a39755d57c8de376
  • Loading branch information
Andrew Leonard authored and gnu-andrew committed Mar 9, 2022
1 parent 11a5bbd commit 673c585
Showing 1 changed file with 11 additions and 5 deletions.
Expand Up @@ -34,18 +34,22 @@
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.LocalDateTime;

* Generate a zip file in a "reproducible" manner from the input zip file.
* Standard zip tools rely on OS file list querying whose ordering can vary
* by platform architecture, this class ensures the zip entries are ordered
* and also supports SOURCE_DATE_EPOCH timestamps.
* and also supports SOURCE_DATE_EPOCH timestamps which will set the ZipEntry
* local time in UTC.
public class MakeZipReproducible {
String input_file = null;
String fname = null;
String zname = "";
long timestamp = -1L;
LocalDateTime timestamp = null;
boolean verbose = false;

// Keep a sorted Set of ZipEntrys to be processed, so that the zip is reproducible
Expand Down Expand Up @@ -117,7 +121,9 @@ boolean parseArgs(String args[]) {
case 't':
// SOURCE_DATE_EPOCH timestamp specified
timestamp = Long.parseLong(args[++count]) * 1000;
long epochSeconds = Long.parseLong(args[++count]);
Instant instant = Instant.ofEpochSecond(epochSeconds);
timestamp = LocalDateTime.ofInstant(instant, ZoneOffset.UTC);
case 'v':
verbose = true;
Expand Down Expand Up @@ -194,8 +200,8 @@ void addEntry(ZipOutputStream zos, ZipEntry entry, InputStream entryInputStream)

// Set to specified timestamp if set otherwise leave as original lastModified time
if (timestamp != -1L) {
if (timestamp != null) {

Expand Down

1 comment on commit 673c585

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.