mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Fix reproducable zips across timezones. (#952)
* Create test for zip timezones * Fix :) * Update ReproducibleBuildTest * Update windows hashes
This commit is contained in:
@@ -30,7 +30,6 @@ import java.io.FileOutputStream;
|
||||
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.gradle.api.tasks.bundling.ZipEntryCompression;
|
||||
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 @@ public class ZipReprocessorUtil {
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -55,13 +55,13 @@ class ReproducibleBuildTest extends Specification implements GradleProjectTestTr
|
||||
|
||||
where:
|
||||
version | modHash | sourceHash
|
||||
DEFAULT_GRADLE | "174c9b52f4bc6d489548d11b42e853cf" | [
|
||||
"5e6e56df303b4fbaaef372d6f143dbfc",
|
||||
"92b6fbffd0bd14bf3c626750eb86c264"
|
||||
DEFAULT_GRADLE | "97240b42385adfaa1952e9c4ea942f71" | [
|
||||
"61438feb9bd548788bbc637637d202fc",
|
||||
"185ad8396d89b726064682bf22572036"
|
||||
]
|
||||
PRE_RELEASE_GRADLE | "174c9b52f4bc6d489548d11b42e853cf" | [
|
||||
"5e6e56df303b4fbaaef372d6f143dbfc",
|
||||
"92b6fbffd0bd14bf3c626750eb86c264"
|
||||
PRE_RELEASE_GRADLE | "97240b42385adfaa1952e9c4ea942f71" | [
|
||||
"61438feb9bd548788bbc637637d202fc",
|
||||
"185ad8396d89b726064682bf22572036"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -155,6 +156,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 +171,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"
|
||||
Checksum.sha1Hex(zip) == "1b06cc0aaa65ab2b0d423fe33431ff5bd14bf9c8"
|
||||
|
||||
where:
|
||||
timezone | _
|
||||
"UTC" | _
|
||||
"US/Central" | _
|
||||
"Europe/London" | _
|
||||
"Australia/Sydney" | _
|
||||
"Etc/GMT-6" | _
|
||||
"Etc/GMT+9" | _
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user