Ensure final download status is always set (#9453)

This commit is contained in:
Two-Ai 2023-05-05 22:17:05 -04:00 committed by GitHub
parent fce9cb820c
commit cb2d43c0d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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