diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt index a1bfd053c..16e51d48a 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt @@ -541,21 +541,19 @@ fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: (( } try { - val uri = DocumentsContract.renameDocument(applicationContext.contentResolver, document.uri, newPath.getFilenameFromPath()) - if (document.uri != uri) { - updateInMediaStore(oldPath, newPath) - rescanPaths(arrayListOf(oldPath, newPath)) { - if (!baseConfig.keepLastModified) { - updateLastModified(newPath, System.currentTimeMillis()) - } - deleteFromMediaStore(oldPath) - runOnUiThread { - callback?.invoke(true) - } + try { + DocumentsContract.renameDocument(applicationContext.contentResolver, document.uri, newPath.getFilenameFromPath()) + } catch (ignored: FileNotFoundException) { + // FileNotFoundException is thrown in some weird cases, but renaming works just fine + } + updateInMediaStore(oldPath, newPath) + rescanPaths(arrayListOf(oldPath, newPath)) { + if (!baseConfig.keepLastModified) { + updateLastModified(newPath, System.currentTimeMillis()) } - } else { + deleteFromMediaStore(oldPath) runOnUiThread { - callback?.invoke(false) + callback?.invoke(true) } } } catch (e: Exception) { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt index 5b0fb96fb..157518a2b 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt @@ -221,7 +221,7 @@ fun Context.getDocumentFile(path: String): DocumentFile? { for (part in parts) { document = document?.findFile(part) } - return document + document } catch (ignored: Exception) { null }