Fix duplicate images after resuming paused downloads (#3504)

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
Mohannad
2026-07-02 21:44:30 +03:00
committed by GitHub
parent ca2e8cf4de
commit f6632940fa
@@ -439,9 +439,7 @@ class Downloader(
// Try to find the image file // Try to find the image file
val imageFile = tmpDir.listFiles()?.firstOrNull { val imageFile = tmpDir.listFiles()?.firstOrNull {
val filename = it.name isDownloadedPageImage(it.name ?: return@firstOrNull false, filename)
if (filename == null || filename.endsWith(".tmp")) return@firstOrNull false
filename.startsWith("$filename.") || filename.startsWith("${filename}__001")
} }
try { try {
@@ -601,6 +599,16 @@ class Downloader(
return downloadedImagesCount == downloadPageCount return downloadedImagesCount == downloadPageCount
} }
/**
* Checks if the file name matches a downloaded page image.
*
* @param fileName Name of the file to check
* @param pagePrefix Expected page prefix (e.g., "001")
*/
private fun isDownloadedPageImage(fileName: String, pagePrefix: String): Boolean =
!fileName.endsWith(".tmp") || fileName.startsWith("$pagePrefix.") ||
fileName.startsWith("${pagePrefix}__001.")
/** /**
* Archive the chapter pages as a CBZ. * Archive the chapter pages as a CBZ.
*/ */