mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-27 11:37:51 +02:00
Fix downloader stopping after failing to create download directory of a manga (#2068)
This commit is contained in:
@ -47,7 +47,8 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
||||
- Fix content under source browse screen top appbar is interactable ([@AntsyLich](https://github.com/AntsyLich)) ([#2026](https://github.com/mihonapp/mihon/pull/2026))
|
||||
- Fix crash when trying use source sort filter without a pre-selection ([@AntsyLich](https://github.com/AntsyLich)) ([#2036](https://github.com/mihonapp/mihon/pull/2036))
|
||||
- Fix empty layout not appearing in browse source screen in some cases ([@NarwhalHorns](https://github.com/NarwhalHorns)) ([#2043](https://github.com/mihonapp/mihon/pull/2043))
|
||||
- Fix Pill not following the local text style ([@AntsyLich](https://github.com/AntsyLich))
|
||||
- Fix Pill not following the local text style ([@AntsyLich](https://github.com/AntsyLich)) ([`f8cb506`](https://github.com/mihonapp/mihon/commit/f8cb506))
|
||||
- Fix downloader stopping after failing to create download directory of a manga ([@AntsyLich](https://github.com/AntsyLich)) ([#2068](https://github.com/mihonapp/mihon/pull/2068))
|
||||
|
||||
### Removed
|
||||
- Remove Okhttp networking from WebView Screen ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#2020](https://github.com/mihonapp/mihon/pull/2020))
|
||||
|
@ -337,7 +337,10 @@ class DownloadManager(
|
||||
*/
|
||||
suspend fun renameChapter(source: Source, manga: Manga, oldChapter: Chapter, newChapter: Chapter) {
|
||||
val oldNames = provider.getValidChapterDirNames(oldChapter.name, oldChapter.scanlator)
|
||||
val mangaDir = provider.getMangaDir(manga.title, source)
|
||||
val mangaDir = provider.getMangaDir(manga.title, source).getOrElse { e ->
|
||||
logcat(LogPriority.ERROR, e) { "Manga download folder doesn't exist. Skipping renaming after source sync" }
|
||||
return
|
||||
}
|
||||
|
||||
// Assume there's only 1 version of the chapter name formats present
|
||||
val oldDownload = oldNames.asSequence()
|
||||
|
@ -14,6 +14,7 @@ import tachiyomi.domain.storage.service.StorageManager
|
||||
import tachiyomi.i18n.MR
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* This class is used to provide the directories where the downloads should be saved.
|
||||
@ -35,20 +36,36 @@ class DownloadProvider(
|
||||
* @param mangaTitle the title of the manga to query.
|
||||
* @param source the source of the manga.
|
||||
*/
|
||||
internal fun getMangaDir(mangaTitle: String, source: Source): UniFile {
|
||||
try {
|
||||
return downloadsDir!!
|
||||
.createDirectory(getSourceDirName(source))!!
|
||||
.createDirectory(getMangaDirName(mangaTitle))!!
|
||||
} catch (e: Throwable) {
|
||||
logcat(LogPriority.ERROR, e) { "Invalid download directory" }
|
||||
throw Exception(
|
||||
context.stringResource(
|
||||
MR.strings.invalid_location,
|
||||
downloadsDir?.displayablePath ?: "",
|
||||
),
|
||||
internal fun getMangaDir(mangaTitle: String, source: Source): Result<UniFile> {
|
||||
val downloadsDir = downloadsDir
|
||||
if (downloadsDir == null) {
|
||||
logcat(LogPriority.ERROR) { "Failed to create download directory" }
|
||||
return Result.failure(
|
||||
IOException(context.stringResource(MR.strings.storage_failed_to_create_download_directory)),
|
||||
)
|
||||
}
|
||||
|
||||
val sourceDirName = getSourceDirName(source)
|
||||
val sourceDir = downloadsDir.createDirectory(sourceDirName)
|
||||
if (sourceDir == null) {
|
||||
val displayablePath = downloadsDir.displayablePath + "/$sourceDirName"
|
||||
logcat(LogPriority.ERROR) { "Failed to create source download directory: $displayablePath" }
|
||||
return Result.failure(
|
||||
IOException(context.stringResource(MR.strings.storage_failed_to_create_directory, displayablePath)),
|
||||
)
|
||||
}
|
||||
|
||||
val mangaDirName = getMangaDirName(mangaTitle)
|
||||
val mangaDir = sourceDir.createDirectory(mangaDirName)
|
||||
if (mangaDir == null) {
|
||||
val displayablePath = sourceDir.displayablePath + "/$mangaDirName"
|
||||
logcat(LogPriority.ERROR) { "Failed to create manga download directory: $displayablePath" }
|
||||
return Result.failure(
|
||||
IOException(context.stringResource(MR.strings.storage_failed_to_create_directory, displayablePath)),
|
||||
)
|
||||
}
|
||||
|
||||
return Result.success(mangaDir)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,7 +315,11 @@ class Downloader(
|
||||
* @param download the chapter to be downloaded.
|
||||
*/
|
||||
private suspend fun downloadChapter(download: Download) {
|
||||
val mangaDir = provider.getMangaDir(download.manga.title, download.source)
|
||||
val mangaDir = provider.getMangaDir(download.manga.title, download.source).getOrElse { e ->
|
||||
download.status = Download.State.ERROR
|
||||
notifier.onError(e.message, download.chapter.name, download.manga.title, download.manga.id)
|
||||
return
|
||||
}
|
||||
|
||||
val availSpace = DiskUtil.getAvailableStorageSpace(mangaDir)
|
||||
if (availSpace != -1L && availSpace < MIN_DISK_SPACE) {
|
||||
|
@ -498,6 +498,8 @@
|
||||
<string name="pref_remove_exclude_categories">Excluded categories</string>
|
||||
<string name="no_location_set">No storage location set</string>
|
||||
<string name="invalid_location">Invalid location: %s</string>
|
||||
<string name="storage_failed_to_create_download_directory">Failed to create download directory</string>
|
||||
<string name="storage_failed_to_create_directory">Failed to create directory: %s</string>
|
||||
<string name="disabled">Disabled</string>
|
||||
<string name="last_read_chapter">Last read chapter</string>
|
||||
<string name="second_to_last">Second to last read chapter</string>
|
||||
|
Reference in New Issue
Block a user