-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GradleInspector: Ignore artifacts of zero byte size #8305
Conversation
This simplifies an upcoming change. Signed-off-by: Frank Viernau <[email protected]>
@@ -87,6 +87,11 @@ private val GRADLE_USER_HOME = Os.env["GRADLE_USER_HOME"]?.let { File(it) } ?: O | |||
*/ | |||
const val OPTION_GRADLE_VERSION = "gradleVersion" | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit message nits:
- Should we say "Maven" instead of "Gradle" artifacts?
- Typo in "rot" -> "root".
/** | ||
* The sha1 sum for a zero by size file. | ||
*/ | ||
private const val ZERO_BYTES_FILE_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have this as EMPTY_PACKAGE_VERIFICATION_CODE
. How about refactoring that first to a constant in HashAlgorithm
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EMPTY_PACKAGE_VERIFICATION_CODE
is in spdx-utils
and does not know about the HashAlgorithm
class. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only used in UtilsTest
which could add the model
as a dependency. I'll propose a follow-up refactoring.
@@ -371,7 +376,11 @@ private fun createRemoteArtifact( | |||
val checksum = okHttpClient.downloadText("$artifactUrl.$algorithm") | |||
.getOrElse { return RemoteArtifact.EMPTY } | |||
|
|||
return RemoteArtifact(artifactUrl, parseChecksum(checksum, algorithm)) | |||
// Ignore file with zero byte size, because it cannot be a valid archive. | |||
val hash = parseChecksum(checksum, algorithm).takeIf { it.value != ZERO_BYTES_FILE_SHA1 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Do better document the expected default, consider takeUnless { it == ZERO_BYTES_FILE_SHA1 }
.
Maven artifacts are archive files. A file with zero bytes size never is a valid archive, so fallback to `RemoteArtifact.EMPTY` in that case. This fixes one possible root cause of #8116. Signed-off-by: Frank Viernau <[email protected]>
6849f66
to
769f34d
Compare
See individual commits.