From a163a6af88627ac034d8616a3df87191eb4db075 Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 4 Nov 2024 16:45:21 -0600 Subject: [PATCH] Fix:Android allow deleting local library item that doesnt exist on device #105 --- .../com/audiobookshelf/app/plugins/AbsFileSystem.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsFileSystem.kt b/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsFileSystem.kt index 29165012..35828180 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsFileSystem.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsFileSystem.kt @@ -196,7 +196,11 @@ class AbsFileSystem : Plugin() { if (localLibraryItem?.folderId?.startsWith("internal-") == true) { Log.d(tag, "Deleting internal library item at absolutePath $absolutePath") val file = File(absolutePath) - success = file.deleteRecursively() + success = if (file.exists()) { + file.deleteRecursively() + } else { + true + } } else { var subfolderPathToDelete = "" localLibraryItem?.folderId?.let { folderId -> @@ -218,7 +222,12 @@ class AbsFileSystem : Plugin() { } val docfile = DocumentFileCompat.fromUri(mainActivity, Uri.parse(contentUrl)) - success = docfile?.delete() == true + if (docfile?.exists() == true) { + success = docfile.delete() == true + } else { + Log.d(tag, "Folder $contentUrl doesn't exist") + success = true + } if (subfolderPathToDelete != "") { Log.d(tag, "Deleting empty subfolder at $subfolderPathToDelete")