From 448a582019308bd740f2fd6fc986bf5410e4111b Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Sun, 28 Jul 2024 11:54:44 +0700 Subject: [PATCH] refactor(source/local): Re-organize updateCover(...) --- .../java/eu/kanade/tachiyomi/source/LocalSource.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index c07fef2a9a..0eb211e935 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -73,11 +73,13 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour } fun updateCover(manga: SManga, input: InputStream): UniFile? { - val dir = getBaseDirectory() ?: return null - var cover = getCoverFile(dir.findFile(manga.url)) - if (cover == null) { - cover = dir.findFile(manga.url)?.createFile(COVER_NAME)!! + val dir = getBaseDirectory()?.findFile(manga.url) + if (dir == null) { + input.close() + return null } + + val cover = getCoverFile(dir) ?: dir.createFile(COVER_NAME)!! // It might not exist if using the external SD card cover.parentFile?.parentFile?.createDirectory(cover.parentFile?.name) input.use {