From 69fdd30a26628dd079a512d7efe44efe47ee1223 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sat, 19 Nov 2022 14:52:29 -0500 Subject: [PATCH] Do not prevent running other deletion tasks when icon does not exist --- app/src/main/java/io/heckel/ntfy/work/DeleteWorker.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/heckel/ntfy/work/DeleteWorker.kt b/app/src/main/java/io/heckel/ntfy/work/DeleteWorker.kt index 01fdebd..d10ffe8 100644 --- a/app/src/main/java/io/heckel/ntfy/work/DeleteWorker.kt +++ b/app/src/main/java/io/heckel/ntfy/work/DeleteWorker.kt @@ -69,7 +69,14 @@ class DeleteWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(ctx Log.d(TAG, "Deleting icons for deleted notifications") val repository = Repository.getInstance(applicationContext) val activeIconUris = repository.getActiveIconUris() - val activeIconFilenames = activeIconUris.map{ fileStat(applicationContext, Uri.parse(it)).filename }.toSet() + val activeIconFilenames = activeIconUris.mapNotNull { + try { + fileStat(applicationContext, Uri.parse(it)).filename + } catch (e: Exception) { + Log.w(TAG, "Unable to stat file $it", e) + null + } + }.toSet() val iconDir = File(applicationContext.cacheDir, DownloadIconWorker.ICON_CACHE_DIR) val allIconFilenames = iconDir.listFiles()?.map{ file -> file.name }.orEmpty() val filenamesToDelete = allIconFilenames.minus(activeIconFilenames)