Fix storing covers for local manga (#6127)

getCoverFile only returns a cover if it already exists, meaning
the block of code to write it from the inputstream never executes.
If getCoverFile returns null, then use previous behaviour of setting
it to cover.jpg so that if the file doesn't exist it's created

(cherry picked from commit f0a5557e60)
This commit is contained in:
Tom Briden
2021-10-30 17:16:29 +01:00
committed by Jobobby04
parent 23fae05694
commit ec6b6ae779
@@ -37,6 +37,7 @@ class LocalSource(private val context: Context) : CatalogueSource {
private val SUPPORTED_ARCHIVE_TYPES = setOf("zip", "rar", "cbr", "cbz", "epub")
private const val COVER_NAME = "cover.jpg"
private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS)
fun updateCover(context: Context, manga: SManga, input: InputStream): File? {
@@ -45,9 +46,11 @@ class LocalSource(private val context: Context) : CatalogueSource {
input.close()
return null
}
val cover = getCoverFile(File("${dir.absolutePath}/${manga.url}"))
if (cover != null && cover.exists()) {
var cover = getCoverFile(File("${dir.absolutePath}/${manga.url}"))
if (cover == null) {
cover = File("${dir.absolutePath}/${manga.url}", COVER_NAME)
}
if (cover != null && !cover.exists()) {
// It might not exist if using the external SD card
cover.parentFile?.mkdirs()
input.use {