Fix issue caused in previous commit.

This commit is contained in:
modmuss50
2023-01-16 21:53:44 +00:00
parent 8a434af084
commit 7f06b64693
2 changed files with 8 additions and 3 deletions

View File

@@ -161,6 +161,12 @@ public class Download {
eTag = readEtag(output);
}
try {
createParentDirs(output.toFile());
} catch (IOException e) {
throw error(e, "Failed to create parent directories");
}
final HttpRequest httpRequest = eTag
.map(this::getETagRequest)
.orElseGet(this::getRequest);
@@ -180,10 +186,9 @@ public class Download {
if (success) {
try {
createParentDirs(output.toFile());
Files.deleteIfExists(output);
} catch (IOException e) {
throw error(e, "Failed to prepare path for download");
throw error(e, "Failed to delete existing file");
}
final long length = Long.parseLong(response.headers().firstValue("Content-Length").orElse("-1"));

View File

@@ -60,7 +60,7 @@ class DownloadFileTest extends DownloadTest {
it.result("Hello World")
}
def output = new File(File.createTempDir(), "file.txt").toPath()
def output = new File(File.createTempDir(), "subdir/file.txt").toPath()
when:
def result = Download.create("$PATH/simpleFile").downloadPath(output)