From 7d52cb7e3caa57af5d54b2eae59136029a5b3605 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 9 Sep 2023 22:32:20 +0100 Subject: [PATCH 1/4] Create test for zip timezones --- .../fabricmc/loom/test/unit/ZipUtilsTest.groovy | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy index 95c469166..e7cf4d428 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy @@ -34,6 +34,8 @@ import net.fabricmc.loom.util.Pair import net.fabricmc.loom.util.ZipReprocessorUtil import net.fabricmc.loom.util.ZipUtils +import java.time.ZoneId + class ZipUtilsTest extends Specification { def "pack"() { given: @@ -155,6 +157,9 @@ class ZipUtilsTest extends Specification { def "append zip entry"() { given: + def currentTimezone = TimeZone.getDefault() + TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of(timezone))) + // Create a reproducible input zip def dir = Files.createTempDirectory("loom-zip-test") def zip = Files.createTempFile("loom-zip-test", ".zip") @@ -167,9 +172,21 @@ class ZipUtilsTest extends Specification { // Add an entry to it ZipReprocessorUtil.appendZipEntry(zip.toFile(), "fabric.mod.json", "Some text".getBytes(StandardCharsets.UTF_8)) + // Reset the timezone back + TimeZone.setDefault(currentTimezone) + then: ZipUtils.unpack(zip, "text.txt") == "hello world".bytes ZipUtils.unpack(zip, "fabric.mod.json") == "Some text".bytes Checksum.sha1Hex(zip) == "232ecda4c770bde8ba618e7a194a4f7b57928dc5" + + where: + timezone | _ + "UTC" | _ + "US/Central" | _ + "Europe/London" | _ + "Australia/Sydney" | _ + "Etc/GMT-6" | _ + "Etc/GMT+9" | _ } } From 60efff54e61c1bbed94c1d791fed97d9eec8f3ad Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 9 Sep 2023 23:49:28 +0100 Subject: [PATCH 2/4] Fix :) --- .../net/fabricmc/loom/util/ZipReprocessorUtil.java | 11 ++--------- .../net/fabricmc/loom/test/unit/ZipUtilsTest.groovy | 5 ++--- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/util/ZipReprocessorUtil.java b/src/main/java/net/fabricmc/loom/util/ZipReprocessorUtil.java index a3b7797a6..d962be8c4 100644 --- a/src/main/java/net/fabricmc/loom/util/ZipReprocessorUtil.java +++ b/src/main/java/net/fabricmc/loom/util/ZipReprocessorUtil.java @@ -30,7 +30,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; -import java.nio.file.attribute.FileTime; import java.util.Calendar; import java.util.Comparator; import java.util.GregorianCalendar; @@ -42,11 +41,6 @@ import org.intellij.lang.annotations.MagicConstant; public class ZipReprocessorUtil { - /** - * See {@link org.gradle.api.internal.file.archive.ZipCopyAction} about this. - */ - private static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = new GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0).getTimeInMillis(); - private ZipReprocessorUtil() { } private static final String MANIFEST_LOCATION = "META-INF/MANIFEST.MF"; @@ -183,9 +177,8 @@ private static void copyZipEntry(ZipOutputStream zipOutputStream, ZipEntry entry } private static void setConstantFileTime(ZipEntry entry) { - entry.setTime(ZipReprocessorUtil.CONSTANT_TIME_FOR_ZIP_ENTRIES); - entry.setLastModifiedTime(FileTime.fromMillis(ZipReprocessorUtil.CONSTANT_TIME_FOR_ZIP_ENTRIES)); - entry.setLastAccessTime(FileTime.fromMillis(ZipReprocessorUtil.CONSTANT_TIME_FOR_ZIP_ENTRIES)); + // See https://github.com/openjdk/jdk/blob/master/test/jdk/java/util/zip/ZipFile/ZipEntryTimeBounds.java + entry.setTime(new GregorianCalendar(1980, Calendar.JANUARY, 1, 0, 0, 0).getTimeInMillis()); } @MagicConstant(valuesFromClass = ZipOutputStream.class) diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy index e7cf4d428..1b40e3f3d 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy @@ -26,6 +26,7 @@ package net.fabricmc.loom.test.unit import java.nio.charset.StandardCharsets import java.nio.file.Files +import java.time.ZoneId import spock.lang.Specification @@ -34,8 +35,6 @@ import net.fabricmc.loom.util.Pair import net.fabricmc.loom.util.ZipReprocessorUtil import net.fabricmc.loom.util.ZipUtils -import java.time.ZoneId - class ZipUtilsTest extends Specification { def "pack"() { given: @@ -178,7 +177,7 @@ class ZipUtilsTest extends Specification { then: ZipUtils.unpack(zip, "text.txt") == "hello world".bytes ZipUtils.unpack(zip, "fabric.mod.json") == "Some text".bytes - Checksum.sha1Hex(zip) == "232ecda4c770bde8ba618e7a194a4f7b57928dc5" + Checksum.sha1Hex(zip) == "1b06cc0aaa65ab2b0d423fe33431ff5bd14bf9c8" where: timezone | _ From 21e50e67022b59259690847f761948aec1995637 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 10 Sep 2023 00:06:52 +0100 Subject: [PATCH 3/4] Update ReproducibleBuildTest --- .../loom/test/integration/ReproducibleBuildTest.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/ReproducibleBuildTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/ReproducibleBuildTest.groovy index f40a65e0d..139efd069 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/ReproducibleBuildTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/ReproducibleBuildTest.groovy @@ -55,12 +55,12 @@ class ReproducibleBuildTest extends Specification implements GradleProjectTestTr where: version | modHash | sourceHash - DEFAULT_GRADLE | "174c9b52f4bc6d489548d11b42e853cf" | [ - "5e6e56df303b4fbaaef372d6f143dbfc", + DEFAULT_GRADLE | "97240b42385adfaa1952e9c4ea942f71" | [ + "61438feb9bd548788bbc637637d202fc", "92b6fbffd0bd14bf3c626750eb86c264" ] - PRE_RELEASE_GRADLE | "174c9b52f4bc6d489548d11b42e853cf" | [ - "5e6e56df303b4fbaaef372d6f143dbfc", + PRE_RELEASE_GRADLE | "97240b42385adfaa1952e9c4ea942f71" | [ + "61438feb9bd548788bbc637637d202fc", "92b6fbffd0bd14bf3c626750eb86c264" ] } From 775e3df3c4acc040dca96b9c260b540bad4d62c4 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 10 Sep 2023 11:03:20 +0100 Subject: [PATCH 4/4] Update windows hashes --- .../loom/test/integration/ReproducibleBuildTest.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/ReproducibleBuildTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/ReproducibleBuildTest.groovy index 139efd069..0936f58f7 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/ReproducibleBuildTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/ReproducibleBuildTest.groovy @@ -57,11 +57,11 @@ class ReproducibleBuildTest extends Specification implements GradleProjectTestTr version | modHash | sourceHash DEFAULT_GRADLE | "97240b42385adfaa1952e9c4ea942f71" | [ "61438feb9bd548788bbc637637d202fc", - "92b6fbffd0bd14bf3c626750eb86c264" + "185ad8396d89b726064682bf22572036" ] PRE_RELEASE_GRADLE | "97240b42385adfaa1952e9c4ea942f71" | [ "61438feb9bd548788bbc637637d202fc", - "92b6fbffd0bd14bf3c626750eb86c264" + "185ad8396d89b726064682bf22572036" ] }