Avoid some crashes
(cherry picked from commit ca065169002475cc92b7736d02340127a5e419bd) # Conflicts: # app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt # app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt
This commit is contained in:
parent
aab5b50070
commit
71eefc3c9e
@ -55,7 +55,7 @@ class CategoryRepositoryImpl(
|
||||
}
|
||||
|
||||
override suspend fun updatePartial(updates: List<CategoryUpdate>) {
|
||||
handler.await(true) {
|
||||
handler.await(inTransaction = true) {
|
||||
for (update in updates) {
|
||||
updatePartialBlocking(update)
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class MangaRepositoryImpl(
|
||||
}
|
||||
|
||||
override suspend fun insert(manga: Manga): Long? {
|
||||
return handler.awaitOneOrNull(true) {
|
||||
return handler.awaitOneOrNull(inTransaction = true) {
|
||||
// SY -->
|
||||
if (mangasQueries.getIdByUrlAndSource(manga.url, manga.source).executeAsOneOrNull() != null) {
|
||||
return@awaitOneOrNull mangasQueries.getIdByUrlAndSource(manga.url, manga.source)
|
||||
|
@ -220,7 +220,7 @@ class DownloadCache(
|
||||
fun removeManga(manga: Manga) {
|
||||
val sourceDir = rootDownloadsDir.sourceDirs[manga.source] ?: return
|
||||
val mangaDirName = provider.getMangaDirName(/* SY --> */ manga.ogTitle /* SY <-- */)
|
||||
if (mangaDirName in sourceDir.mangaDirs) {
|
||||
if (sourceDir.mangaDirs.containsKey(mangaDirName)) {
|
||||
sourceDir.mangaDirs -= mangaDirName
|
||||
}
|
||||
|
||||
@ -286,9 +286,8 @@ class DownloadCache(
|
||||
val mangaDirs = sourceDir.dir.listFiles().orEmpty()
|
||||
.filterNot { it.name.isNullOrBlank() }
|
||||
.associate { it.name!! to MangaDirectory(it) }
|
||||
.toMutableMap()
|
||||
|
||||
sourceDir.mangaDirs = mangaDirs
|
||||
sourceDir.mangaDirs = ConcurrentHashMap(mangaDirs)
|
||||
|
||||
mangaDirs.values.forEach { mangaDir ->
|
||||
val chapterDirs = mangaDir.dir.listFiles().orEmpty()
|
||||
@ -325,7 +324,7 @@ class DownloadCache(
|
||||
/**
|
||||
* Returns a new map containing only the key entries of [transform] that are not null.
|
||||
*/
|
||||
private inline fun <K, V, R> Map<out K, V>.mapNotNullKeys(transform: (Map.Entry<K?, V>) -> R?): MutableMap<R, V> {
|
||||
private inline fun <K, V, R> Map<out K, V>.mapNotNullKeys(transform: (Map.Entry<K?, V>) -> R?): ConcurrentHashMap<R, V> {
|
||||
val mutableMap = ConcurrentHashMap<R, V>()
|
||||
forEach { element -> transform(element)?.let { mutableMap[it] = element.value } }
|
||||
return mutableMap
|
||||
@ -337,7 +336,7 @@ class DownloadCache(
|
||||
*/
|
||||
private class RootDirectory(
|
||||
val dir: UniFile,
|
||||
var sourceDirs: MutableMap<Long, SourceDirectory> = mutableMapOf(),
|
||||
var sourceDirs: ConcurrentHashMap<Long, SourceDirectory> = ConcurrentHashMap(),
|
||||
)
|
||||
|
||||
/**
|
||||
@ -345,7 +344,7 @@ private class RootDirectory(
|
||||
*/
|
||||
private class SourceDirectory(
|
||||
val dir: UniFile,
|
||||
var mangaDirs: MutableMap<String, MangaDirectory> = mutableMapOf(),
|
||||
var mangaDirs: ConcurrentHashMap<String, MangaDirectory> = ConcurrentHashMap(),
|
||||
)
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user