Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

[bug] Fix crash in Android Navigator aggregated mode #125

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class MetadataStorage(
) : FolderStorage<Metadata>(
"metadata", scope, path, MonoidIsNotUsed()
) {

override fun isNeutral(value: Metadata): Boolean = false

override suspend fun valueToBinary(value: Metadata): ByteArray {
Expand All @@ -32,9 +33,10 @@ internal class MetadataStorage(

override suspend fun valueFromBinary(raw: ByteArray): Metadata {
val text = String(raw, Charsets.UTF_8)
val json = Json.parseToJsonElement(text)
if (text.isEmpty()) return Metadata.Unknown()

val kind = json.jsonObject[KIND]!!.jsonPrimitive.content
val json = Json.parseToJsonElement(text)
val kind = json.jsonObject[KIND]?.jsonPrimitive?.content ?: return Metadata.Unknown()

val metadata = when (Kind.valueOf(kind)) {
Kind.IMAGE ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.arkbuilders.arklib.data.storage

import android.os.Build
import android.util.Log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -12,10 +13,10 @@ import java.nio.file.Path
import java.nio.file.attribute.FileTime
import java.time.Instant
import java.util.concurrent.ConcurrentHashMap
import java.util.stream.Collectors
import kotlin.io.path.deleteIfExists
import kotlin.io.path.isDirectory
import kotlin.io.path.relativeTo
import kotlin.streams.toList

abstract class FolderStorage<V>(
private val label: String,
Expand Down Expand Up @@ -78,7 +79,7 @@ abstract class FolderStorage<V>(
val newTimestamps: ConcurrentHashMap<ResourceId, FileTime> =
ConcurrentHashMap()

val jobs = Files.list(storageFolder)
val stream = Files.list(storageFolder)
.filter { !it.isDirectory() }
.map { path ->
Log.v(logPrefix, "reading value from $path")
Expand All @@ -101,7 +102,13 @@ abstract class FolderStorage<V>(
newTimestamps[id] = newTimestamp
}
}
}.toList()
}

val jobs = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
stream.toList()
} else {
stream.collect(Collectors.toList())
}

jobs.joinAll()

Expand Down
Loading