From 2bfa39c6a25032fc6a4b094014bfc7245902f4ec Mon Sep 17 00:00:00 2001 From: Logan Gorence Date: Sun, 16 Jan 2022 13:11:36 -0800 Subject: [PATCH] Fix download for setupPaperServer. --- .../kubelet/foundation/gradle/SmartDownloader.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/cloud/kubelet/foundation/gradle/SmartDownloader.kt b/buildSrc/src/main/kotlin/cloud/kubelet/foundation/gradle/SmartDownloader.kt index 2869d76..209b43c 100644 --- a/buildSrc/src/main/kotlin/cloud/kubelet/foundation/gradle/SmartDownloader.kt +++ b/buildSrc/src/main/kotlin/cloud/kubelet/foundation/gradle/SmartDownloader.kt @@ -5,13 +5,18 @@ import java.nio.file.Files import java.nio.file.Path import java.security.MessageDigest -class SmartDownloader(val localFilePath: Path, val remoteDownloadUrl: URI, val sha256: String) { +class SmartDownloader( + private val localFilePath: Path, + private val remoteDownloadUrl: URI, + private val sha256: String +) { fun download(): Boolean { - if (checkLocalFileHash() == HashResult.ValidHash) { + val hashResult = checkLocalFileHash() + if (hashResult != HashResult.ValidHash) { downloadRemoteFile() - return true + return false } - return false + return true } private fun downloadRemoteFile() { @@ -19,7 +24,8 @@ class SmartDownloader(val localFilePath: Path, val remoteDownloadUrl: URI, val s val remoteFileStream = url.openStream() val localFileStream = Files.newOutputStream(localFilePath) remoteFileStream.transferTo(localFileStream) - if (checkLocalFileHash() != HashResult.ValidHash) { + val hashResult = checkLocalFileHash() + if (hashResult != HashResult.ValidHash) { throw RuntimeException("Download of $remoteDownloadUrl did not result in valid hash.") } }