From 163724a3cbedc188a14e942d5419b7d0b57e15e9 Mon Sep 17 00:00:00 2001 From: Adam Ahmed Date: Thu, 8 Feb 2024 16:37:51 +0000 Subject: [PATCH] Add protection for 0 byte cache entries --- .../androidx/build/gradle/s3buildcache/S3BuildCacheService.kt | 1 + .../androidx/build/gradle/s3buildcache/S3StorageService.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt index ccfd549..9b9ae41 100644 --- a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt +++ b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt @@ -69,6 +69,7 @@ class S3BuildCacheService( } override fun store(key: BuildCacheKey, writer: BuildCacheEntryWriter) { + if (writer.size == 0L) return // do not store empty entries into the cache logger.info("Storing ${key.blobKey()}") val cacheKey = key.blobKey() val output = ByteArrayOutputStream() diff --git a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3StorageService.kt b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3StorageService.kt index 85a032c..365fc3b 100644 --- a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3StorageService.kt +++ b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3StorageService.kt @@ -131,6 +131,7 @@ class S3StorageService( return try { val inputStream = client.getObject(request) val blob = inputStream.response() ?: return null + if (blob.contentLength() == 0L) return null // return empty entries as a cache miss if (blob.contentLength() > sizeThreshold) { val path = FileHandleInputStream.create() val outputStream = path.outputStream()