aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authoreuxane2024-09-18 23:41:13 +0200
committereuxane2024-09-18 23:41:13 +0200
commite13a563ec8e195f7043f0379ba03ac76583909b2 (patch)
tree54e5673a29dc42ef9b6c14e02a437166e0c74b65 /app/src
parent962e805f2e5336749475962f6bb9f5b28cb67063 (diff)
downloadtincapp-e13a563ec8e195f7043f0379ba03ac76583909b2.tar.gz
storageprovider: fix virtual root handling for documentIdForFile
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt12
1 files changed, 8 insertions, 4 deletions
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() {
166 } 166 }
167 167
168 private fun documentIdForFile(file: File): String = 168 private fun documentIdForFile(file: File): String =
169 if (AppPaths.confDir().isParentOf(file)) { 169 if (AppPaths.confDir().isParentOf(file, false)) {
170 File(VIRTUAL_ROOT_NETWORKS, file.pathUnder(AppPaths.confDir())).path 170 File(VIRTUAL_ROOT_NETWORKS, file.pathUnder(AppPaths.confDir())).path
171 } else if (AppPaths.logDir().isParentOf(file)) { 171 } else if (AppPaths.logDir().isParentOf(file, false)) {
172 File(VIRTUAL_ROOT_LOG, file.pathUnder(AppPaths.logDir())).path 172 File(VIRTUAL_ROOT_LOG, file.pathUnder(AppPaths.logDir())).path
173 } else { 173 } else {
174 throw IllegalArgumentException() 174 throw IllegalArgumentException()
@@ -177,8 +177,12 @@ class FilesDocumentsProvider : DocumentsProvider() {
177 private fun File.pathUnder(parent: File): String = 177 private fun File.pathUnder(parent: File): String =
178 canonicalPath.removePrefix(parent.canonicalPath) 178 canonicalPath.removePrefix(parent.canonicalPath)
179 179
180 private fun File.isParentOf(childCandidate: File): Boolean { 180 private fun File.isParentOf(childCandidate: File, strict: Boolean = true): Boolean {
181 var parentOfChild = childCandidate.canonicalFile.parentFile 181 var parentOfChild = childCandidate.canonicalFile
182
183 if (strict)
184 parentOfChild = parentOfChild.parentFile
185
182 while (parentOfChild != null) { 186 while (parentOfChild != null) {
183 if (parentOfChild.equals(canonicalFile)) return true 187 if (parentOfChild.equals(canonicalFile)) return true
184 parentOfChild = parentOfChild.parentFile 188 parentOfChild = parentOfChild.parentFile