From c32bb510ba5f140edf3589b0d06b6b5a7f954210 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:14:08 -0600 Subject: [PATCH] Improve logging for deleteMatchingSubtitles This works on debug but not prerelease so I am adding more logging to try and figure out why here --- .../cloudstream3/utils/SubtitleUtils.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleUtils.kt index 93a53395..04757bee 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleUtils.kt @@ -2,8 +2,10 @@ package com.lagradost.cloudstream3.utils import android.content.Context import com.lagradost.api.Log +import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.utils.VideoDownloadManager.getFolder import com.lagradost.safefile.SafeFile +import java.io.IOException object SubtitleUtils { @@ -21,8 +23,20 @@ object SubtitleUtils { getFolder(context, relative, info.basePath)?.forEach { (name, uri) -> if (isMatchingSubtitle(name, display, cleanDisplay)) { val subtitleFile = SafeFile.fromUri(context, uri) - if (subtitleFile == null || !subtitleFile.delete()) { - Log.e("SubtitleDeletion", "Failed to delete subtitle file: ${subtitleFile?.name()}") + try { + subtitleFile?.deleteOrThrow() + if (subtitleFile == null) { + Log.e( + "SubtitleDeletion", + "Failed to delete unknown subtitle file" + ) + } + } catch (ex: IOException) { + Log.e( + "SubtitleDeletion", + "Failed to delete subtitle file: ${subtitleFile?.name()}" + ) + logError(ex) } } }