mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-22 16:39:45 -07:00
Fix downloads not being found for sources sharing a stored source's name
This commit is contained in:
@@ -186,7 +186,8 @@ class DownloadCache(
|
||||
fun getTotalDownloadCount(): Int {
|
||||
renewCache()
|
||||
|
||||
return rootDownloadsDir.sourceDirs.values.sumOf { sourceDir ->
|
||||
// The disk index stores a folder shared by several ids once per id
|
||||
return rootDownloadsDir.sourceDirs.values.distinctBy { it.dir?.uri }.sumOf { sourceDir ->
|
||||
sourceDir.mangaDirs.values.sumOf { mangaDir ->
|
||||
mangaDir.chapterDirs.size
|
||||
}
|
||||
@@ -390,20 +391,21 @@ class DownloadCache(
|
||||
sources = getSources()
|
||||
}
|
||||
|
||||
val sourceMap = sources.associate { provider.getSourceDirName(it).lowercase() to it.id }
|
||||
// A stored stub can share its name with an installed source, so a folder can belong to several ids
|
||||
val sourceIdsByDirName = sources.groupBy({ provider.getSourceDirName(it).lowercase() }, { it.id })
|
||||
|
||||
rootDownloadsDirMutex.withLock {
|
||||
val updatedRootDir = RootDirectory(storageManager.getDownloadsDirectory())
|
||||
|
||||
updatedRootDir.sourceDirs = updatedRootDir.dir?.listFiles().orEmpty()
|
||||
.filter { it.isDirectory && !it.name.isNullOrBlank() }
|
||||
.mapNotNull { dir ->
|
||||
val sourceId = sourceMap[dir.name!!.lowercase()]
|
||||
sourceId?.let { it to SourceDirectory(dir) }
|
||||
.flatMap { dir ->
|
||||
val sourceDir = SourceDirectory(dir)
|
||||
sourceIdsByDirName[dir.name!!.lowercase()].orEmpty().map { it to sourceDir }
|
||||
}
|
||||
.toMap()
|
||||
|
||||
updatedRootDir.sourceDirs.values.map { sourceDir ->
|
||||
updatedRootDir.sourceDirs.values.distinct().map { sourceDir ->
|
||||
async {
|
||||
sourceDir.mangaDirs = sourceDir.dir?.listFiles().orEmpty()
|
||||
.filter { it.isDirectory && !it.name.isNullOrBlank() }
|
||||
|
||||
Reference in New Issue
Block a user