From 01d4c8f593c81561fd1a15f836cb1e75020b6dc9 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Tue, 11 Aug 2020 17:13:20 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Ignore=20unreadable=20files=20wh?= =?UTF-8?q?en=20hasing=20(and=20print=20warning)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/github/burrunan/gradle/hashFiles.kt | 13 ++++++++++--- .../github/burrunan/gradle/hashing/HashDetails.kt | 10 ++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/layered-cache/src/main/kotlin/com/github/burrunan/gradle/hashFiles.kt b/layered-cache/src/main/kotlin/com/github/burrunan/gradle/hashFiles.kt index 60afbcb..53b0859 100644 --- a/layered-cache/src/main/kotlin/com/github/burrunan/gradle/hashFiles.kt +++ b/layered-cache/src/main/kotlin/com/github/burrunan/gradle/hashFiles.kt @@ -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 @@ -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( diff --git a/layered-cache/src/main/kotlin/com/github/burrunan/gradle/hashing/HashDetails.kt b/layered-cache/src/main/kotlin/com/github/burrunan/gradle/hashing/HashDetails.kt index fc67b9c..4e998f0 100644 --- a/layered-cache/src/main/kotlin/com/github/burrunan/gradle/hashing/HashDetails.kt +++ b/layered-cache/src/main/kotlin/com/github/burrunan/gradle/hashing/HashDetails.kt @@ -15,6 +15,7 @@ */ package com.github.burrunan.gradle.hashing +import actions.core.warning import crypto.createHash import fs.createReadStream import fs2.promises.stat @@ -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") }