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
This commit is contained in:
Tom Briden 2021-10-30 17:16:29 +01:00 committed by GitHub
parent 58a871c8cc
commit f0a5557e60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,6 +39,7 @@ class LocalSource(private val context: Context) : CatalogueSource {
private val SUPPORTED_ARCHIVE_TYPES = setOf("zip", "rar", "cbr", "cbz", "epub") 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) private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS)
fun updateCover(context: Context, manga: SManga, input: InputStream): File? { fun updateCover(context: Context, manga: SManga, input: InputStream): File? {
@ -47,9 +48,11 @@ class LocalSource(private val context: Context) : CatalogueSource {
input.close() input.close()
return null return null
} }
val cover = getCoverFile(File("${dir.absolutePath}/${manga.url}")) var cover = getCoverFile(File("${dir.absolutePath}/${manga.url}"))
if (cover == null) {
if (cover != null && cover.exists()) { cover = File("${dir.absolutePath}/${manga.url}", COVER_NAME)
}
if (cover != null && !cover.exists()) {
// It might not exist if using the external SD card // It might not exist if using the external SD card
cover.parentFile?.mkdirs() cover.parentFile?.mkdirs()
input.use { input.use {