Skip to content

Commit

Permalink
GH-1902 Save generated checksums as hex (Fix #1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Aug 8, 2023
1 parent 40394a7 commit 959744d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Expand Up @@ -46,10 +46,10 @@ class Repository internal constructor(
val sha256 = location.resolveSibling(location.getSimpleName() + ".sha256")
val sha512 = location.resolveSibling(location.getSimpleName() + ".sha512")

return storageProvider.putFile(md5, DigestUtils.md5(bytes).inputStream())
.flatMap { storageProvider.putFile(sha1, DigestUtils.sha1(bytes).inputStream()) }
.flatMap { storageProvider.putFile(sha256, DigestUtils.sha256(bytes).inputStream()) }
.flatMap { storageProvider.putFile(sha512, DigestUtils.sha512(bytes).inputStream()) }
return storageProvider.putFile(md5, DigestUtils.md5Hex(bytes).byteInputStream())
.flatMap { storageProvider.putFile(sha1, DigestUtils.sha1Hex(bytes).byteInputStream()) }
.flatMap { storageProvider.putFile(sha256, DigestUtils.sha256Hex(bytes).byteInputStream()) }
.flatMap { storageProvider.putFile(sha512, DigestUtils.sha512Hex(bytes).byteInputStream()) }
}

@Deprecated(message = "Use Repository#storageProvider")
Expand Down
Expand Up @@ -90,7 +90,10 @@ data class Location private constructor(private val uri: String) {
uri.substringAfterLast(delimiter, defaultValue ?: uri).toLocation()

fun getParent(): Location =
uri.substringBeforeLast("/").toLocation()
when (uri.contains("/")) {
true -> uri.substringBeforeLast("/").toLocation()
else -> empty()
}

fun getExtension(): String =
getSimpleName().getExtension()
Expand Down
Expand Up @@ -71,14 +71,14 @@ class ChecksumPlugin : ReposilitePlugin() {

val generatedChecksum = data.use {
when (checksum) {
MD5 -> DigestUtils.md5(data)
SHA1 -> DigestUtils.sha1(data)
SHA256 -> DigestUtils.sha256(data)
SHA512 -> DigestUtils.sha512(data)
MD5 -> DigestUtils.md5Hex(data)
SHA1 -> DigestUtils.sha1Hex(data)
SHA256 -> DigestUtils.sha256Hex(data)
SHA512 -> DigestUtils.sha512Hex(data)
}
}

repository.storageProvider.putFile(checksumGav, generatedChecksum.inputStream())
repository.storageProvider.putFile(checksumGav, generatedChecksum.byteInputStream())
.peek { logger.debug("Checksum | Generated checksum ${checksum.name} for $file") }
.onError { logger.debug("Checksum | Cannot generate checksum ${checksum.name} for $file due to $it") }
}
Expand Down

0 comments on commit 959744d

Please sign in to comment.