Skip to content

Commit

Permalink
8279182: MakeZipReproducible ZipEntry timestamps not localized to UTC
Browse files Browse the repository at this point in the history
Reviewed-by: erikj
  • Loading branch information
Andrew Leonard committed Dec 23, 2021
1 parent 558a682 commit bc0466c
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,22 @@
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
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[]) {
break;
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);
break;
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) {
entry.setTime(timestamp);
if (timestamp != null) {
entry.setTimeLocal(timestamp);
}

zos.putNextEntry(entry);
Expand Down

3 comments on commit bc0466c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@andrew-m-leonard
Copy link

Choose a reason for hiding this comment

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

@openjdk
Copy link

@openjdk openjdk bot commented on bc0466c Mar 7, 2022

Choose a reason for hiding this comment

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

@andrew-m-leonard the backport was successfully created on the branch andrew-m-leonard-backport-bc0466c7 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit bc0466c7 from the openjdk/jdk repository.

The commit being backported was authored by Andrew Leonard on 23 Dec 2021 and was reviewed by Erik Joelsson.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev andrew-m-leonard-backport-bc0466c7:andrew-m-leonard-backport-bc0466c7
$ git checkout andrew-m-leonard-backport-bc0466c7
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev andrew-m-leonard-backport-bc0466c7

Please sign in to comment.