Skip to content

Commit

Permalink
Fix: truncate the existing file if our new one is smaller than the ol…
Browse files Browse the repository at this point in the history
…d one
  • Loading branch information
Gegy committed Nov 4, 2023
1 parent 2a2376e commit dbe1efc
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class SimpleHttpClient {
private static final Logger LOGGER = LogManager.getLogger();
Expand Down Expand Up @@ -106,7 +109,7 @@ private CompletableFuture<?> downloadFile(final String host, final ServerManifes
.header("User-Agent", USER_AGENT)
.GET()
.build();
return client.sendAsync(request, HttpResponse.BodyHandlers.ofFile(targetPath))
return client.sendAsync(request, HttpResponse.BodyHandlers.ofFile(targetPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING))
.thenAccept(response -> LaunchEnvironmentHandler.INSTANCE.addProgressMessage("Finished downloading file: " + fileName));
}

Expand Down

0 comments on commit dbe1efc

Please sign in to comment.