Skip to content

Commit

Permalink
Add exception message to hashFiles(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Aug 11, 2020
1 parent 29d2590 commit d5f863c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class HashResult(
val totalBytes: Int,
)

suspend fun hashFiles(vararg paths: String, algorithm: String = "sha1"): HashResult {
suspend fun hashFiles(vararg paths: String, algorithm: String = "sha1"): HashResult = try {
val globber = create(paths.joinToString("\n")).await()
val fileNames = globber.glob().await()
fileNames.sort()
Expand Down Expand Up @@ -62,9 +62,11 @@ suspend fun hashFiles(vararg paths: String, algorithm: String = "sha1"): HashRes
}
}
hash.end()
return HashResult(
HashResult(
hash = hash.digest("hex"),
numFiles = numFiles,
totalBytes = totalBytes,
)
} catch (e: Throwable) {
throw IllegalArgumentException("Unable to hash ${paths.joinToString(", ")}", e)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private fun sha1FromModulesFileName(key: String): String {
return key.substring(hashStart, lastSlash).padStart(40, '0')
}

suspend fun hashFilesDetailed(vararg paths: String, algorithm: String = "sha1"): HashDetails {
suspend fun hashFilesDetailed(vararg paths: String, algorithm: String = "sha1"): HashDetails = try {
val globber = create(paths.joinToString("\n")).await()
val fileNames = globber.glob().await()
// Sorting is needed for stable overall hash
Expand Down Expand Up @@ -103,8 +103,10 @@ suspend fun hashFilesDetailed(vararg paths: String, algorithm: String = "sha1"):
overallHash.update(key)
overallHash.update(digest)
}
return HashDetails(
HashDetails(
HashInfo(totalBytes, overallHash.digest("hex"), files.size),
HashContents(files),
)
} catch (e: Throwable) {
throw IllegalArgumentException("Unable to hash ${paths.joinToString(", ")}", e)
}

0 comments on commit d5f863c

Please sign in to comment.