diff --git a/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMap.kt b/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMap.kt index 080171ee4f2..36ed73d9b01 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMap.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMap.kt @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.utils.Printer import java.io.File abstract class BasicMap, V>( - storageFile: File, + internal val storageFile: File, keyDescriptor: KeyDescriptor, valueExternalizer: DataExternalizer ) { diff --git a/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMap.kt.191 b/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMap.kt.191 index f8c0bd0e49e..83a99190a19 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMap.kt.191 +++ b/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMap.kt.191 @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.utils.Printer import java.io.File abstract class BasicMap, V>( - storageFile: File, + internal val storageFile: File, keyDescriptor: KeyDescriptor, valueExternalizer: DataExternalizer ) { diff --git a/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMapsOwner.kt b/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMapsOwner.kt index 1f91bbda3a2..571f26bb968 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMapsOwner.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/storage/BasicMapsOwner.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.incremental.storage import org.jetbrains.annotations.TestOnly import java.io.File +import java.io.IOException open class BasicMapsOwner(val cachesDir: File) { private val maps = arrayListOf>() @@ -35,16 +36,35 @@ open class BasicMapsOwner(val cachesDir: File) { } open fun clean() { - maps.forEach { it.clean() } + forEachMapSafe("clean", BasicMap<*, *>::clean) } open fun close() { - maps.forEach { it.close() } + forEachMapSafe("close", BasicMap<*, *>::close) } open fun flush(memoryCachesOnly: Boolean) { - maps.forEach { it.flush(memoryCachesOnly) } + forEachMapSafe("flush") { it.flush(memoryCachesOnly) } } - @TestOnly fun dump(): String = maps.joinToString("\n\n") { it.dump() } + private fun forEachMapSafe(actionName: String, action: (BasicMap<*, *>) -> Unit) { + val actionExceptions = LinkedHashMap() + maps.forEach { + try { + action(it) + } catch (e: Exception) { + actionExceptions[it.storageFile.name] = e + } + } + if (actionExceptions.isNotEmpty()) { + val desc = "Could not $actionName incremental caches in $cachesDir: ${actionExceptions.keys.joinToString(", ")}" + val allIOExceptions = actionExceptions.all { it is IOException } + val ex = if (allIOExceptions) IOException(desc) else Exception(desc) + actionExceptions.forEach { (_, e) -> ex.addSuppressed(e) } + throw ex + } + } + + @TestOnly + fun dump(): String = maps.joinToString("\n\n") { it.dump() } } \ No newline at end of file diff --git a/build-common/src/org/jetbrains/kotlin/incremental/storage/CachingLazyStorage.kt b/build-common/src/org/jetbrains/kotlin/incremental/storage/CachingLazyStorage.kt index b2175875b0f..360a4e517b1 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/storage/CachingLazyStorage.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/storage/CachingLazyStorage.kt @@ -79,11 +79,10 @@ class CachingLazyStorage( override fun clean() { try { storage?.close() - } catch (ignored: Throwable) { + } finally { + PersistentHashMap.deleteFilesStartingWith(storageFile) + storage = null } - - PersistentHashMap.deleteFilesStartingWith(storageFile) - storage = null } @Synchronized