[K/N] Fixed a data race during monolithic caches creation
For per-file caches the data race is still there, but since per-file caches are only used for incremental compilation, it's ok to leave it as is for now (we cope with the data race by using a separate folder for each Gradle task).
This commit is contained in:
+11
-7
@@ -14,13 +14,17 @@ internal class CacheStorage(private val generationState: NativeGenerationState)
|
||||
private val outputFiles = generationState.outputFiles
|
||||
|
||||
companion object {
|
||||
fun renameOutput(outputFiles: OutputFiles) {
|
||||
// For caches the output file is a directory. It might be created by someone else,
|
||||
// we have to delete it in order for the next renaming operation to succeed.
|
||||
val tempDirectoryForRemoval = File(outputFiles.mainFileName + "-to-remove")
|
||||
if (outputFiles.mainFile.exists && !outputFiles.mainFile.renameTo(tempDirectoryForRemoval))
|
||||
return
|
||||
tempDirectoryForRemoval.deleteRecursively()
|
||||
fun renameOutput(outputFiles: OutputFiles, overwrite: Boolean) {
|
||||
if (outputFiles.mainFile.exists) {
|
||||
if (!overwrite)
|
||||
return
|
||||
// For caches the output file is a directory. It might be already created,
|
||||
// we have to delete it in order for the next renaming operation to succeed.
|
||||
val tempDirectoryForRemoval = File(outputFiles.mainFileName + "-to-remove")
|
||||
if (!outputFiles.mainFile.renameTo(tempDirectoryForRemoval))
|
||||
return
|
||||
tempDirectoryForRemoval.deleteRecursively()
|
||||
}
|
||||
if (!outputFiles.tempCacheDirectory!!.renameTo(outputFiles.mainFile))
|
||||
outputFiles.tempCacheDirectory.deleteRecursively()
|
||||
}
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ internal val SaveAdditionalCacheInfoPhase = createSimpleNamedCompilerPhase<Nativ
|
||||
internal val FinalizeCachePhase = createSimpleNamedCompilerPhase<PhaseContext, OutputFiles>(
|
||||
name = "FinalizeCache",
|
||||
description = "Finalize cache (rename temp to the final dist)"
|
||||
) { _, outputFiles ->
|
||||
) { context, outputFiles ->
|
||||
// TODO: Explicit parameter
|
||||
CacheStorage.renameOutput(outputFiles)
|
||||
CacheStorage.renameOutput(outputFiles, overwrite = context.config.producePerFileCache)
|
||||
}
|
||||
Reference in New Issue
Block a user