diff --git a/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt b/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt index 36fca0352..971ea6d77 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt @@ -56,6 +56,7 @@ import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withPermit import moe.tarsin.coroutines.runSuspendCatching +import okio.FileNotFoundException import okio.Path import splitties.init.appCtx @@ -642,7 +643,9 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS }.onFailure { spiderDen.removeIntermediateFiles(index) logcat(WORKER_DEBUG_TAG) { "Download image $index attempt #$times failed" } - if (it is CancellationException) throw it + when (it) { + is CancellationException, is FileNotFoundException -> throw it + } error = it.displayString() } } diff --git a/app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt b/app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt index 8dcb609b4..4837a1351 100644 --- a/app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt +++ b/app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt @@ -11,6 +11,7 @@ import android.webkit.MimeTypeMap import androidx.core.database.getLongOrNull import okio.FileHandle import okio.FileMetadata +import okio.FileNotFoundException import okio.FileSystem import okio.IOException import okio.Path @@ -37,7 +38,7 @@ class AndroidFileSystem(context: Context) : FileSystem() { // ExternalStorageProvider always throw exception when renameDocument on API 28 // https://android.googlesource.com/platform/frameworks/base/+/7bf90408e36613a84dc2a665905fde2c83cfa797 if (Build.VERSION.SDK_INT != Build.VERSION_CODES.P) { - throw IOException("Failed to move $source to $target") + throw FileNotFoundException("Failed to move $source to $target") } } } @@ -89,7 +90,7 @@ class AndroidFileSystem(context: Context) : FileSystem() { throw IOException("Failed to delete $path") } } else if (mustExist) { - throw IOException("$path does not exist") + throw FileNotFoundException("$path does not exist") } } @@ -133,7 +134,7 @@ class AndroidFileSystem(context: Context) : FileSystem() { dir / displayName } } - }.getOrElse { if (throwOnFailure) throw IOException("Failed to list $dir") else null } + }.getOrElse { if (throwOnFailure) throw FileNotFoundException("Failed to list $dir") else null } } override fun metadataOrNull(path: Path): FileMetadata? { @@ -196,7 +197,7 @@ class AndroidFileSystem(context: Context) : FileSystem() { DocumentsContract.createDocument(contentResolver, parent.toUri(), mimeType, displayName) } contentResolver.openFileDescriptor(path.toUri(), mode) - }.getOrNull() ?: throw IOException("Failed to open file: $path") + }.getOrNull() ?: throw FileNotFoundException("Failed to open file: $path") } }