Check the actual folder when deleting source folder in case of stale cache
(cherry picked from commit f9bbbce466310147927ffb7317f432e2f3fc478a) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt
This commit is contained in:
parent
25ac8a3a70
commit
359d855e21
@ -6,7 +6,6 @@ import com.hippo.unifile.UniFile
|
|||||||
import eu.kanade.domain.manga.model.Manga
|
import eu.kanade.domain.manga.model.Manga
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.source.Source
|
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
@ -114,15 +113,6 @@ class DownloadCache(
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if source has download
|
|
||||||
*
|
|
||||||
* @param source the source to check.
|
|
||||||
*/
|
|
||||||
fun sourceHasDownload(source: Source): Boolean {
|
|
||||||
return rootDir.files[source.id]?.files?.size?.let { it > 0 } ?: false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the cache needs a renewal and performs it if needed.
|
* Checks if the cache needs a renewal and performs it if needed.
|
||||||
*/
|
*/
|
||||||
@ -139,18 +129,14 @@ class DownloadCache(
|
|||||||
*/
|
*/
|
||||||
private fun renew() {
|
private fun renew() {
|
||||||
// SY -->
|
// SY -->
|
||||||
val onlineSources = sourceManager.getVisibleOnlineSources()
|
val sources = sourceManager.getVisibleOnlineSources() + sourceManager.getStubSources()
|
||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
val stubSources = sourceManager.getStubSources()
|
|
||||||
|
|
||||||
val allSource = onlineSources + stubSources
|
|
||||||
|
|
||||||
val sourceDirs = rootDir.dir.listFiles()
|
val sourceDirs = rootDir.dir.listFiles()
|
||||||
.orEmpty()
|
.orEmpty()
|
||||||
.associate { it.name to SourceDirectory(it) }
|
.associate { it.name to SourceDirectory(it) }
|
||||||
.mapNotNullKeys { entry ->
|
.mapNotNullKeys { entry ->
|
||||||
allSource.find { provider.getSourceDirName(it).equals(entry.key, ignoreCase = true) }?.id
|
sources.find { provider.getSourceDirName(it).equals(entry.key, ignoreCase = true) }?.id
|
||||||
}
|
}
|
||||||
|
|
||||||
rootDir.files = sourceDirs
|
rootDir.files = sourceDirs
|
||||||
|
@ -281,14 +281,20 @@ class DownloadManager(
|
|||||||
val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source)
|
val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source)
|
||||||
chapterDirs.forEach { it.delete() }
|
chapterDirs.forEach { it.delete() }
|
||||||
cache.removeChapters(filteredChapters, manga)
|
cache.removeChapters(filteredChapters, manga)
|
||||||
if (cache.getDownloadCount(manga) == 0) { // Delete manga directory if empty
|
|
||||||
|
// Delete manga directory if empty
|
||||||
|
if (cache.getDownloadCount(manga) == 0) {
|
||||||
chapterDirs.firstOrNull()?.parentFile?.delete()
|
chapterDirs.firstOrNull()?.parentFile?.delete()
|
||||||
cache.removeManga(manga)
|
cache.removeManga(manga)
|
||||||
}
|
}
|
||||||
if (!cache.sourceHasDownload(source)) { // Delete source directory if empty
|
|
||||||
provider.findSourceDir(source)?.delete()
|
// Delete source directory if empty
|
||||||
|
val sourceDir = provider.findSourceDir(source)
|
||||||
|
if (sourceDir?.listFiles()?.isEmpty() == true) {
|
||||||
|
sourceDir.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filteredChapters
|
return filteredChapters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user