diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CacheStorage.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CacheStorage.kt index 7c110b44a97..776cc66f6f0 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CacheStorage.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CacheStorage.kt @@ -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() } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/CacheBuilding.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/CacheBuilding.kt index e9141c42685..1ffb250b880 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/CacheBuilding.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/CacheBuilding.kt @@ -45,7 +45,7 @@ internal val SaveAdditionalCacheInfoPhase = createSimpleNamedCompilerPhase( 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) } \ No newline at end of file