From 78734fbb1349f87abad86da25d499f7a3308d3db Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:48:31 -0600 Subject: [PATCH] Fix race condition --- .../com/lagradost/cloudstream3/utils/VideoDownloadManager.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt index 109c1ac0..4d146ac3 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt @@ -1794,12 +1794,14 @@ object VideoDownloadManager { private fun deleteFile(context: Context, id: Int): Boolean { val info = context.getKey(KEY_DOWNLOAD_INFO, id.toString()) ?: return false + val file = info.toFile(context) + downloadEvent.invoke(id to DownloadActionType.Stop) downloadProgressEvent.invoke(Triple(id, 0, 0)) downloadStatusEvent.invoke(id to DownloadType.IsStopped) downloadDeleteEvent.invoke(id) - val isFileDeleted = info.toFile(context)?.delete() ?: false + val isFileDeleted = file?.delete() == true || file?.exists() == false if (isFileDeleted) deleteMatchingSubtitles(context, info) return isFileDeleted