From 2d10e42f4dd3e8e1becb8885a17f261313d9e76e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Mon, 16 Jan 2023 18:25:59 +0000 Subject: [PATCH] Fix broken etag handling. Maybe fixes #802 --- .../net/fabricmc/loom/util/download/Download.java | 14 +++++++------- .../test/unit/download/DownloadFileTest.groovy | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/util/download/Download.java b/src/main/java/net/fabricmc/loom/util/download/Download.java index ad643bc7..a1f3158a 100644 --- a/src/main/java/net/fabricmc/loom/util/download/Download.java +++ b/src/main/java/net/fabricmc/loom/util/download/Download.java @@ -161,13 +161,6 @@ public class Download { eTag = readEtag(output); } - try { - createParentDirs(output.toFile()); - Files.deleteIfExists(output); - } catch (IOException e) { - throw error(e, "Failed to prepare path for download"); - } - final HttpRequest httpRequest = eTag .map(this::getETagRequest) .orElseGet(this::getRequest); @@ -186,6 +179,13 @@ public class Download { } if (success) { + try { + createParentDirs(output.toFile()); + Files.deleteIfExists(output); + } catch (IOException e) { + throw error(e, "Failed to prepare path for download"); + } + final long length = Long.parseLong(response.headers().firstValue("Content-Length").orElse("-1")); AtomicLong totalBytes = new AtomicLong(0); diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/download/DownloadFileTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/download/DownloadFileTest.groovy index e3ee8d08..f0b39f69 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/download/DownloadFileTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/download/DownloadFileTest.groovy @@ -203,7 +203,7 @@ class DownloadFileTest extends DownloadTest { def output = new File(File.createTempDir(), "etag.txt").toPath() when: - for (i in 0..<2) { + for (i in 0..<3) { Download.create("$PATH/etag") .etag(true) .downloadPath(output)