From e13a563ec8e195f7043f0379ba03ac76583909b2 Mon Sep 17 00:00:00 2001 From: euxane Date: Wed, 18 Sep 2024 23:41:13 +0200 Subject: storageprovider: fix virtual root handling for documentIdForFile --- .../pacien/tincapp/storageprovider/FilesDocumentsProvider.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt b/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt index 38cd562..8b8e2a7 100644 --- a/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt +++ b/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt @@ -166,9 +166,9 @@ class FilesDocumentsProvider : DocumentsProvider() { } private fun documentIdForFile(file: File): String = - if (AppPaths.confDir().isParentOf(file)) { + if (AppPaths.confDir().isParentOf(file, false)) { File(VIRTUAL_ROOT_NETWORKS, file.pathUnder(AppPaths.confDir())).path - } else if (AppPaths.logDir().isParentOf(file)) { + } else if (AppPaths.logDir().isParentOf(file, false)) { File(VIRTUAL_ROOT_LOG, file.pathUnder(AppPaths.logDir())).path } else { throw IllegalArgumentException() @@ -177,8 +177,12 @@ class FilesDocumentsProvider : DocumentsProvider() { private fun File.pathUnder(parent: File): String = canonicalPath.removePrefix(parent.canonicalPath) - private fun File.isParentOf(childCandidate: File): Boolean { - var parentOfChild = childCandidate.canonicalFile.parentFile + private fun File.isParentOf(childCandidate: File, strict: Boolean = true): Boolean { + var parentOfChild = childCandidate.canonicalFile + + if (strict) + parentOfChild = parentOfChild.parentFile + while (parentOfChild != null) { if (parentOfChild.equals(canonicalFile)) return true parentOfChild = parentOfChild.parentFile -- cgit v1.2.3