From 3d21ce811bd958e5f65db30147bda4c70aedd9af Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Fri, 17 May 2019 12:59:40 +0200 Subject: [PATCH] fix DownloadUtil not downloading file if ETag present, but file is not --- .../loom/providers/MinecraftProvider.java | 11 ++++++++++- .../net/fabricmc/loom/util/DownloadUtil.java | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java index a2e20aa..4a7d986 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java @@ -42,6 +42,7 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Optional; import java.util.function.Consumer; +import java.util.zip.ZipError; public class MinecraftProvider extends DependencyProvider { @@ -89,7 +90,15 @@ public class MinecraftProvider extends DependencyProvider { libraryProvider.provide(this, project); if (!MINECRAFT_MERGED_JAR.exists()) { - mergeJars(project.getLogger()); + try { + mergeJars(project.getLogger()); + } catch (ZipError e) { + DownloadUtil.delete(MINECRAFT_CLIENT_JAR); + DownloadUtil.delete(MINECRAFT_SERVER_JAR); + + project.getLogger().error("Could not merge JARs! Deleting source JARs - please re-run the command and move on.", e); + throw new RuntimeException(); + } } } diff --git a/src/main/java/net/fabricmc/loom/util/DownloadUtil.java b/src/main/java/net/fabricmc/loom/util/DownloadUtil.java index f17ba84..9d06730 100644 --- a/src/main/java/net/fabricmc/loom/util/DownloadUtil.java +++ b/src/main/java/net/fabricmc/loom/util/DownloadUtil.java @@ -86,7 +86,7 @@ public class DownloadUtil { } long modifyTime = connection.getHeaderFieldDate("Last-Modified", -1); - if (code == HttpURLConnection.HTTP_NOT_MODIFIED || modifyTime > 0 && to.exists() && to.lastModified() >= modifyTime) { + if (to.exists() && (code == HttpURLConnection.HTTP_NOT_MODIFIED || modifyTime > 0 && to.lastModified() >= modifyTime)) { if (!quiet) logger.info("'{}' Not Modified, skipping.", to); return; //What we've got is already fine } @@ -180,4 +180,20 @@ public class DownloadUtil { return String.format("%.2f GB", bytes / (1024.0 * 1024.0 * 1024.0)); } } + + /** + * Delete the file along with the corresponding ETag, if it exists. + * + * @param file The file to delete. + */ + public static void delete(File file) { + if (file.exists()) { + file.delete(); + } + + File etagFile = getETagFile(file); + if (etagFile.exists()) { + etagFile.delete(); + } + } } \ No newline at end of file