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 d9b2706..46d9530 100644 --- a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3StorageService.kt +++ b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3StorageService.kt @@ -100,9 +100,13 @@ class S3StorageService( } override fun validateConfiguration() { - val buckets = client.listBuckets().buckets() - if (buckets.none { bucket -> bucket.name() == bucketName }) { - throw Exception("Bucket $bucketName under project $region cannot be found or it is not accessible using the provided credentials") + try { + val buckets = client.listBuckets().buckets() + if (buckets.none { bucket -> bucket.name() == bucketName }) { + throw Exception("Bucket $bucketName under project $region cannot be found or is not accessible using the provided credentials") + } + } catch (e: Exception) { + logger.warn("Couldn't validate S3 client config: ${e.message}") } } @@ -127,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() @@ -162,7 +167,12 @@ class S3StorageService( } private fun delete(client: S3Client, request: DeleteObjectRequest): Boolean { - return client.deleteObject(request).deleteMarker() + return try { + client.deleteObject(request).deleteMarker() + } catch (e: Exception) { + logger.debug("Unable to delete $request", e) + false + } } } }