diff options
author | vmishenev <vad-mishenev@yandex.ru> | 2021-10-30 01:26:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-30 01:26:12 +0300 |
commit | f63134d218ea6975ac63329e5dbe70b9487f0276 (patch) | |
tree | f0f771a701eaa943292a4eb58fef3faa782d6f4a /plugins/base/src/main | |
parent | 100947b7e622336180980754142d042a495d1a0e (diff) | |
download | dokka-f63134d218ea6975ac63329e5dbe70b9487f0276.tar.gz dokka-f63134d218ea6975ac63329e5dbe70b9487f0276.tar.bz2 dokka-f63134d218ea6975ac63329e5dbe70b9487f0276.zip |
Fix `FileWriter` concurrency (#2205)
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/FileWriter.kt | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/FileWriter.kt b/plugins/base/src/main/kotlin/renderers/FileWriter.kt index f8c0e882..9fcd3eb5 100644 --- a/plugins/base/src/main/kotlin/renderers/FileWriter.kt +++ b/plugins/base/src/main/kotlin/renderers/FileWriter.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka.base.renderers import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext import org.jetbrains.dokka.plugability.DokkaContext import java.io.File @@ -10,15 +12,12 @@ import java.nio.file.* class FileWriter(val context: DokkaContext): OutputWriter { private val createdFiles: MutableSet<String> = mutableSetOf() + private val createdFilesMutex = Mutex() private val jarUriPrefix = "jar:file:" private val root = context.configuration.outputDir override suspend fun write(path: String, text: String, ext: String) { - if (createdFiles.contains(path)) { - context.logger.error("An attempt to write ${root}/$path several times!") - return - } - createdFiles.add(path) + if (checkFileCreated(path)) return try { val dir = Paths.get(root.absolutePath, path.dropLastWhile { it != '/' }).toFile() @@ -32,6 +31,15 @@ class FileWriter(val context: DokkaContext): OutputWriter { } } + private suspend fun checkFileCreated(path: String): Boolean = createdFilesMutex.withLock { + if (createdFiles.contains(path)) { + context.logger.error("An attempt to write ${root}/$path several times!") + return true + } + createdFiles.add(path) + return false + } + override suspend fun writeResources(pathFrom: String, pathTo: String) = if (javaClass.getResource(pathFrom)?.toURI()?.toString()?.startsWith(jarUriPrefix) == true) { copyFromJar(pathFrom, pathTo) |