Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash in DownloadService if trying to read dead download item #5903

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface DownloadDao {
suspend fun findById(videoId: String): DownloadWithItems

@Query("SELECT * FROM downloaditem WHERE id = :id")
suspend fun findDownloadItemById(id: Int): DownloadItem
suspend fun findDownloadItemById(id: Int): DownloadItem?

@Query("DELETE FROM downloaditem WHERE id = :id")
suspend fun deleteDownloadItemById(id: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import kotlin.io.path.fileSize
import kotlin.math.min
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
Expand Down Expand Up @@ -341,7 +340,8 @@
}

lifecycleScope.launch(coroutineContext) {
downloadFile(Database.downloadDao().findDownloadItemById(id))
val file = Database.downloadDao().findDownloadItemById(id) ?: return@launch
downloadFile(file)
}
}

Expand All @@ -361,16 +361,14 @@
/**
* Stop downloading job for given [id]. If no downloads are active, stop the service.
*/
private fun stop(id: Int) = CoroutineScope(Dispatchers.IO).launch {
private fun stop(id: Int) = lifecycleScope.launch(coroutineContext) {

Check failure on line 364 in app/src/main/java/com/github/libretube/services/DownloadService.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/services/DownloadService.kt:364:33: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)

Check failure on line 364 in app/src/main/java/com/github/libretube/services/DownloadService.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Newline expected before expression body Raw Output: app/src/main/java/com/github/libretube/services/DownloadService.kt:364:33: error: Newline expected before expression body (standard:function-signature)
downloadQueue[id] = false
_downloadFlow.emit(id to DownloadStatus.Stopped)

lifecycleScope.launch {
val item = Database.downloadDao().findDownloadItemById(id)
notificationManager.cancel(item.getNotificationId())
Database.downloadDao().deleteDownloadItemById(id)
stopServiceIfDone()
}
val item = Database.downloadDao().findDownloadItemById(id) ?: return@launch
notificationManager.cancel(item.getNotificationId())
Database.downloadDao().deleteDownloadItemById(id)
stopServiceIfDone()
}

/**
Expand Down
Loading