Fix broken etag handling. Maybe fixes #802

This commit is contained in:
modmuss50
2023-01-16 18:25:59 +00:00
parent 2b9072f37d
commit 2d10e42f4d
2 changed files with 8 additions and 8 deletions

View File

@@ -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);

View File

@@ -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)