Skip to content

Commit

Permalink
fix(gradle-inspector): Keep the artifact URL on invalid hash values
Browse files Browse the repository at this point in the history
Do not return `RemoteArtifact.EMPTY` early on invalid hash values but
maintain at least the artifact URL in any case.

As logging now is not only done for zero size artifacts but any failure,
also raise the log level from `info` to `warn`.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Sep 11, 2024
1 parent 7c421cc commit 78f0a07
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,18 @@ private fun createRemoteArtifact(
}

// TODO: How to handle authentication for private repositories here, or rely on Gradle for the download?
val checksum = okHttpClient.downloadText("$artifactUrl.$algorithm")
.getOrElse { return RemoteArtifact.EMPTY }

val hash = parseChecksum(checksum, algorithm)
val hash = okHttpClient.downloadText("$artifactUrl.$algorithm")
.mapCatching { checksum ->
parseChecksum(checksum, algorithm).also {
require(it.value != HashAlgorithm.SHA1.emptyValue) {
"Ignoring invalid artifact of zero size at $artifactUrl."
}
}
}.getOrElse {
logger.warn("Unable to get a valid artifact checksum.", it)

// Ignore file with zero byte size, because it cannot be a valid archive.
if (hash.value == HashAlgorithm.SHA1.emptyValue) {
logger.info { "Ignoring zero byte size artifact: $artifactUrl" }
return RemoteArtifact.EMPTY
}
Hash.NONE
}

return RemoteArtifact(artifactUrl, hash)
}
Expand Down

0 comments on commit 78f0a07

Please sign in to comment.