Skip to content

Commit

Permalink
🥅 Ignore unreadable files when hasing (and print warning)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Aug 11, 2020
1 parent 6d3e893 commit 01d4c8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.github.burrunan.gradle

import actions.core.warning
import crypto.createHash
import actions.glob.create
import com.github.burrunan.wrappers.nodejs.pipe
Expand Down Expand Up @@ -55,11 +56,17 @@ suspend fun hashFiles(vararg paths: String, algorithm: String = "sha1"): HashRes
numFiles += 1
totalBytes += statSync.size.toInt()
// Add filename
hash.update(key, "utf8")

fs.createReadStream(name).use {
it.pipe(hash, end = false)
try {
fs.createReadStream(name).use {
it.pipe(hash, end = false)
}
} catch (e: Throwable) {
warning("Unable to hash $name, will ignore the file: ${e.stackTraceToString()}")
continue
}

hash.update(key, "utf8")
}
hash.end()
HashResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.github.burrunan.gradle.hashing

import actions.core.warning
import crypto.createHash
import fs.createReadStream
import fs2.promises.stat
Expand Down Expand Up @@ -92,8 +93,13 @@ suspend fun hashFilesDetailed(vararg paths: String, algorithm: String = "sha1"):
key.substringAfterLast('/')
else -> {
val hash = createHash(algorithm)
createReadStream(name).use {
it.pipe(hash)
try {
createReadStream(name).use {
it.pipe(hash)
}
} catch (e: Throwable) {
warning("Unable to hash $name, will ignore the file: ${e.stackTraceToString()}")
continue
}
hash.digest().toString("hex")
}
Expand Down

0 comments on commit 01d4c8f

Please sign in to comment.