Ensure final download status is always set (#9453)

(cherry picked from commit cb2d43c0d15b6d16b5a8522388f1cedf2fc29a16)
This commit is contained in:
Two-Ai 2023-05-05 22:17:05 -04:00 committed by Jobobby04
parent 277c19eb36
commit 20ee365bdc

View File

@ -537,9 +537,15 @@ class Downloader(
dirname: String,
) {
// Page list hasn't been initialized
val downloadPageCount = download.pages?.size ?: return
// Ensure that all pages has been downloaded
if (download.downloadedImages < downloadPageCount) return
val downloadPageCount = download.pages?.size ?: run {
download.status = Download.State.ERROR
return
}
// Ensure that all pages have been downloaded
if (download.downloadedImages != downloadPageCount) {
download.status = Download.State.ERROR
return
}
// Ensure that the chapter folder has all the pages
val downloadedImagesCount = tmpDir.listFiles().orEmpty().count {
val fileName = it.name.orEmpty()
@ -551,8 +557,11 @@ class Downloader(
else -> true
}
}
if (downloadedImagesCount != downloadPageCount) {
download.status = Download.State.ERROR
return
}
download.status = if (downloadedImagesCount == downloadPageCount) {
createComicInfoFile(
tmpDir,
download.manga,
@ -570,10 +579,7 @@ class Downloader(
DiskUtil.createNoMediaFile(tmpDir, context)
Download.State.DOWNLOADED
} else {
Download.State.ERROR
}
download.status = Download.State.DOWNLOADED
}
/**