aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/renderers/FileWriter.kt18
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)