Skip to content

Commit

Permalink
fix(extractor): Don't include time in kzips for java (#4085)
Browse files Browse the repository at this point in the history
Don't include time in kzips so diffs only compare the contents of the kzip, not when it was created.
  • Loading branch information
salguarnieri authored Sep 16, 2019
1 parent e2202c5 commit 3c25f1a
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
public final class KZipWriter implements KZip.Writer {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();

// Constant time used so time information is not stored in the kzip. This way files can be diff'd
// and they will only be different if the contents are different.
private static final long MODIFIED_TIME = 0;
private static final KZip.Encoding DEFAULT_ENCODING;

static {
Expand Down Expand Up @@ -76,6 +79,7 @@ public KZipWriter(File file, KZip.Encoding encoding, Gson gson) throws IOExcepti
// Add an entry for the root directory prefix (required by the spec).
ZipEntry root = new ZipEntry(descriptor.root() + "/");
root.setComment("kzip root directory");
root.setTime(MODIFIED_TIME);
this.output.putNextEntry(root);
this.output.closeEntry();

Expand Down Expand Up @@ -120,6 +124,7 @@ public String writeFile(byte[] data) throws IOException {
private void appendZip(byte[] data, String path) throws IOException {
if (pathsWritten.add(path)) {
ZipEntry entry = new ZipEntry(path);
entry.setTime(MODIFIED_TIME);
output.putNextEntry(entry);
output.write(data);
output.closeEntry();
Expand Down

0 comments on commit 3c25f1a

Please sign in to comment.