From c4a476d0d25ea724f658ab5fa2df889fab19bbf3 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 1 Jan 2022 15:20:35 -0500 Subject: [PATCH] Handle renaming existing downloaded CBZ chapters on update --- .../tachiyomi/data/download/DownloadManager.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index d6c0ae41d6..dc23395801 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -327,15 +327,19 @@ class DownloadManager( */ fun renameChapter(source: Source, manga: Manga, oldChapter: Chapter, newChapter: Chapter) { val oldNames = provider.getValidChapterDirNames(oldChapter) - val newName = provider.getChapterDirName(newChapter) val mangaDir = provider.getMangaDir(manga, source) // Assume there's only 1 version of the chapter name formats present - val oldFolder = oldNames.asSequence() + val oldDownload = oldNames.asSequence() .mapNotNull { mangaDir.findFile(it) } - .firstOrNull() + .firstOrNull() ?: return - if (oldFolder?.renameTo(newName) == true) { + var newName = provider.getChapterDirName(newChapter) + if (oldDownload.isFile && oldDownload.name?.endsWith(".cbz") == true) { + newName += ".cbz" + } + + if (oldDownload.renameTo(newName)) { cache.removeChapter(oldChapter, manga) cache.addChapter(newName, mangaDir, manga) } else {