Skip to content

Commit ff6ef9c

Browse files
authored
Merge pull request #44 from oheyadam/better-offline-support
Better offline support in AWS implementation
2 parents 84256cb + 739fb18 commit ff6ef9c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class S3BuildCacheService(
6969
}
7070

7171
override fun store(key: BuildCacheKey, writer: BuildCacheEntryWriter) {
72+
if (writer.size == 0L) return // do not store empty entries into the cache
7273
logger.info("Storing ${key.blobKey()}")
7374
val cacheKey = key.blobKey()
7475
val output = ByteArrayOutputStream()

s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3StorageService.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ class S3StorageService(
100100
}
101101

102102
override fun validateConfiguration() {
103-
val buckets = client.listBuckets().buckets()
104-
if (buckets.none { bucket -> bucket.name() == bucketName }) {
105-
throw Exception("Bucket $bucketName under project $region cannot be found or it is not accessible using the provided credentials")
103+
try {
104+
val buckets = client.listBuckets().buckets()
105+
if (buckets.none { bucket -> bucket.name() == bucketName }) {
106+
throw Exception("Bucket $bucketName under project $region cannot be found or is not accessible using the provided credentials")
107+
}
108+
} catch (e: Exception) {
109+
logger.warn("Couldn't validate S3 client config: ${e.message}")
106110
}
107111
}
108112

@@ -127,6 +131,7 @@ class S3StorageService(
127131
return try {
128132
val inputStream = client.getObject(request)
129133
val blob = inputStream.response() ?: return null
134+
if (blob.contentLength() == 0L) return null // return empty entries as a cache miss
130135
if (blob.contentLength() > sizeThreshold) {
131136
val path = FileHandleInputStream.create()
132137
val outputStream = path.outputStream()
@@ -162,7 +167,12 @@ class S3StorageService(
162167
}
163168

164169
private fun delete(client: S3Client, request: DeleteObjectRequest): Boolean {
165-
return client.deleteObject(request).deleteMarker()
170+
return try {
171+
client.deleteObject(request).deleteMarker()
172+
} catch (e: Exception) {
173+
logger.debug("Unable to delete $request", e)
174+
false
175+
}
166176
}
167177
}
168178
}

0 commit comments

Comments
 (0)