Skip to content

Commit a818c94

Browse files
authored
cf: log warning rather than failing when unknown file hash algo (#459)
1 parent 4c94c19 commit a818c94

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ private Mono<ResolveResult> downloadOrResolveFile(InstallContext context, CurseF
807807

808808
if (locatedFile != null) {
809809
log.info("Mod file {} already exists", locatedFile);
810-
return FileHashVerifier.verify(locatedFile, cfFile.getHashes())
810+
return verifyHash(cfFile, locatedFile)
811811
.map(ResolveResult::new);
812812
}
813813
else {
@@ -817,7 +817,7 @@ private Mono<ResolveResult> downloadOrResolveFile(InstallContext context, CurseF
817817
}
818818

819819
return context.cfApi.download(cfFile, outputFile, modFileDownloadStatusHandler(this.outputDir, log))
820-
.flatMap(path -> FileHashVerifier.verify(path, cfFile.getHashes()))
820+
.flatMap(path -> verifyHash(cfFile, path))
821821
.map(ResolveResult::new)
822822
.onErrorResume(
823823
e -> e instanceof FailedRequestException
@@ -827,6 +827,16 @@ private Mono<ResolveResult> downloadOrResolveFile(InstallContext context, CurseF
827827
}
828828
}
829829

830+
private static Mono<Path> verifyHash(CurseForgeFile cfFile, Path path) {
831+
return FileHashVerifier.verify(path, cfFile.getHashes())
832+
.onErrorResume(IllegalArgumentException.class::isInstance,
833+
e -> {
834+
log.warn("Unable to process hash for mod {}: {}", cfFile, e.getMessage());
835+
return Mono.just(path);
836+
}
837+
);
838+
}
839+
830840
private Mono<ResolveResult> handleFileNeedingManualDownload(CurseForgeMod modInfo, boolean isWorld, CurseForgeFile cfFile,
831841
Path outputFile
832842
) {

src/main/java/me/itzg/helpers/curseforge/FileHashVerifier.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public class FileHashVerifier {
2424
algos.put(HashAlgo.Sha1, ChecksumAlgo.SHA1);
2525
}
2626

27+
/**
28+
* @return Mono.error with {@link FileHashInvalidException}
29+
* or {@link IllegalArgumentException} when compatible checksum algorithm can't be found
30+
*/
2731
public static Mono<Path> verify(Path file, List<FileHash> hashes) {
2832
if (hashes.isEmpty()) {
2933
return Mono.just(file);

0 commit comments

Comments
 (0)