Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import me.itzg.helpers.errors.InvalidParameterException;
import me.itzg.helpers.fabric.FabricLauncherInstaller;
import me.itzg.helpers.files.Manifests;
import me.itzg.helpers.files.ReactiveFileUtils;
import me.itzg.helpers.files.ResultsFileWriter;
import me.itzg.helpers.forge.ForgeInstaller;
import me.itzg.helpers.forge.ForgeInstallerResolver;
Expand Down Expand Up @@ -763,10 +764,15 @@ private Mono<PathWithInfo> downloadAndPostProcess(
private Mono<DownloadOrResolveResult> buildRetryableDownload(InstallContext context,
CurseForgeMod modInfo, CurseForgeFile cfFile, boolean isWorld, Path outputSubdir
) {
final Path outputFile = resolveOutputFile(outputSubdir, cfFile);

// use defer so that the download mono is rebuilt on each retry
return Mono.defer(() ->
downloadOrResolveFile(context, modInfo, isWorld, outputSubdir, cfFile)
.checkpoint()
.onErrorResume(throwable ->
ReactiveFileUtils.removeFailedDownload(throwable, outputFile)
)
)
// retry the deferred part above if one of the expected failure cases
.retryWhen(
Expand All @@ -778,8 +784,10 @@ private Mono<DownloadOrResolveResult> buildRetryableDownload(InstallContext con
throwable instanceof ChannelException
)
.doBeforeRetry(retrySignal ->
log.warn("Retrying to download {} @ {}:{}",
cfFile.getFileName(), modInfo.getName(), cfFile.getDisplayName()
log.warn("Retry #{} download of {} @ {}:{} due to {}",
retrySignal.totalRetries() + 1,
cfFile.getFileName(), modInfo.getName(), cfFile.getDisplayName(),
retrySignal.failure().getClass().getSimpleName()
)
)
);
Expand All @@ -799,7 +807,7 @@ static class DownloadOrResolveResult {
private Mono<DownloadOrResolveResult> downloadOrResolveFile(InstallContext context, CurseForgeMod modInfo,
boolean isWorld, Path outputSubdir, CurseForgeFile cfFile
) {
final Path outputFile = outputSubdir.resolve(cfFile.getFileName());
final Path outputFile = resolveOutputFile(outputSubdir, cfFile);

// Will try to locate an existing file by alternate names that browser might create,
// but only for non-world files of the modpack
Expand Down Expand Up @@ -829,6 +837,10 @@ private Mono<DownloadOrResolveResult> downloadOrResolveFile(InstallContext conte
}
}

private static @NotNull Path resolveOutputFile(Path outputSubdir, CurseForgeFile cfFile) {
return outputSubdir.resolve(cfFile.getFileName());
}

/**
* @return Mono.error with {@link FileHashInvalidException} when not valid
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ public void installUsingVersions(

fabricMetaClient.resolveInstallerVersion(installerVersion)
.doOnNext(v -> log.debug("Resolved installer version {} from {}", v, installerVersion))
.flatMap(resolvedInstallerVersion -> downloadResolvedLauncher(
fabricMetaClient,
resolvedMinecraftVersion,
resolvedLoaderVersion,
resolvedInstallerVersion
))
.flatMap(resolvedInstallerVersion ->
downloadResolvedLauncher(
fabricMetaClient,
resolvedMinecraftVersion,
resolvedLoaderVersion,
resolvedInstallerVersion
)
)
.checkpoint("downloadResolvedLauncher")
)
)
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/me/itzg/helpers/files/ReactiveFileUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.itzg.helpers.files;

import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -84,4 +85,26 @@ public static Mono<Long> writeByteBufFluxToFile(ByteBufFlux byteBufFlux, Path fi
// Just expose the total bytes read from network
.map(Tuple2::getT2);
}

/**
* Used with {@link reactor.core.publisher.Mono#onErrorResume(java.util.function.Function)}
* @param throwable the throwable to pass to the returned mono
* @param outputFile the file to remove, if present
* @return an error mono with the given throwable as cause
* @param <T> the type of the surrounding reactive chain
*/
public static <T> Mono<T> removeFailedDownload(Throwable throwable, Path outputFile) {
return Mono.<T>create(sink -> {
try {
log.trace("Removing failed download of {}", outputFile);
if (Files.deleteIfExists(outputFile)) {
log.debug("Removed failed download of {}", outputFile);
}
} catch (IOException e) {
log.error("Unable to remove failed download of {}", outputFile, e);
}
sink.error(throwable);
})
.subscribeOn(Schedulers.boundedElastic());
}
}
2 changes: 1 addition & 1 deletion src/main/java/me/itzg/helpers/http/SharedFetchArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setPendingAcquireTimeout(Duration timeout) {
optionsBuilder.pendingAcquireTimeout(timeout);
}

@Option(names = "--use-http2", defaultValue = "${env:FETCH_USE_HTTP2:-true}",
@Option(names = "--use-http2", defaultValue = "${env:FETCH_USE_HTTP2:-false}",
description = "Whether to use HTTP/2. Default: ${DEFAULT-VALUE}"
)
public void setUseHttp2(boolean useHttp2) {
Expand Down