From 3868d415be6eb4abe31f5652095809d269ae429f Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Tue, 29 Aug 2023 01:11:07 +0200 Subject: [PATCH] Do not reuse "FolderProvider" in "ArchiveProviders" download function Due to reusing the "FolderProvider" to download a chapter as a cbz file, a normal chapter download folder was created. In case the download was aborted before the cbz file got created and the folder deleted, the next time the chapter got downloaded, the wrong "FileProvider" was selected, causing the chapter not to get downloaded as a cbz file. --- .../fileProvider/impl/ArchiveProvider.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/fileProvider/impl/ArchiveProvider.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/fileProvider/impl/ArchiveProvider.kt index fd3c60e68..5b021dc7d 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/fileProvider/impl/ArchiveProvider.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/fileProvider/impl/ArchiveProvider.kt @@ -9,8 +9,8 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream import org.apache.commons.compress.archivers.zip.ZipFile import suwayomi.tachidesk.manga.impl.download.fileProvider.ChaptersFilesProvider import suwayomi.tachidesk.manga.impl.download.model.DownloadChapter +import suwayomi.tachidesk.manga.impl.util.getChapterCachePath import suwayomi.tachidesk.manga.impl.util.getChapterCbzPath -import suwayomi.tachidesk.manga.impl.util.getChapterDownloadPath import java.io.File import java.io.InputStream @@ -29,20 +29,19 @@ class ArchiveProvider(mangaId: Int, chapterId: Int) : ChaptersFilesProvider(mang scope: CoroutineScope, step: suspend (DownloadChapter?, Boolean) -> Unit ): Boolean { - val chapterDir = getChapterDownloadPath(mangaId, chapterId) val outputFile = File(getChapterCbzPath(mangaId, chapterId)) - val chapterFolder = File(chapterDir) - if (outputFile.exists()) handleExistingCbzFile(outputFile, chapterFolder) + val chapterCacheFolder = File(getChapterCachePath(mangaId, chapterId)) + if (outputFile.exists()) handleExistingCbzFile(outputFile, chapterCacheFolder) - FolderProvider(mangaId, chapterId).download().execute(download, scope, step) + super.downloadImpl(download, scope, step) withContext(Dispatchers.IO) { outputFile.createNewFile() } ZipArchiveOutputStream(outputFile.outputStream()).use { zipOut -> - if (chapterFolder.isDirectory) { - chapterFolder.listFiles()?.sortedBy { it.name }?.forEach { + if (chapterCacheFolder.isDirectory) { + chapterCacheFolder.listFiles()?.sortedBy { it.name }?.forEach { val entry = ZipArchiveEntry(it.name) try { zipOut.putArchiveEntry(entry) @@ -56,8 +55,8 @@ class ArchiveProvider(mangaId: Int, chapterId: Int) : ChaptersFilesProvider(mang } } - if (chapterFolder.exists() && chapterFolder.isDirectory) { - chapterFolder.deleteRecursively() + if (chapterCacheFolder.exists() && chapterCacheFolder.isDirectory) { + chapterCacheFolder.deleteRecursively() } return true