summaryrefslogtreecommitdiff
path: root/libs/documents/src/main/java/org/the_jk/cleversync
diff options
context:
space:
mode:
Diffstat (limited to 'libs/documents/src/main/java/org/the_jk/cleversync')
-rw-r--r--libs/documents/src/main/java/org/the_jk/cleversync/io/documents/DocumentDirectory.kt14
1 files changed, 12 insertions, 2 deletions
diff --git a/libs/documents/src/main/java/org/the_jk/cleversync/io/documents/DocumentDirectory.kt b/libs/documents/src/main/java/org/the_jk/cleversync/io/documents/DocumentDirectory.kt
index 258d5b6..e8b94aa 100644
--- a/libs/documents/src/main/java/org/the_jk/cleversync/io/documents/DocumentDirectory.kt
+++ b/libs/documents/src/main/java/org/the_jk/cleversync/io/documents/DocumentDirectory.kt
@@ -17,6 +17,7 @@ import org.the_jk.cleversync.io.ModifiableDirectory
import org.the_jk.cleversync.io.ModifiableFile
import org.the_jk.cleversync.io.ModifiableLink
import java.io.IOException
+import java.nio.file.FileAlreadyExistsException
import kotlin.time.Duration
internal open class DocumentDirectory(
@@ -103,6 +104,7 @@ internal open class DocumentDirectory(
override fun createDirectory(name: String): ModifiableDirectory {
if (!metadata.supportsCreate()) throw IOException("Directory doesn't support creation")
+ if (findChild(name) != null) throw FileAlreadyExistsException(name)
val documentUri = DocumentsContract.createDocument(
contentResolver,
DocumentsContract.buildDocumentUriUsingTree(treeUri, metadata.documentId),
@@ -118,6 +120,7 @@ internal open class DocumentDirectory(
override fun createFile(name: String): ModifiableFile {
if (!metadata.supportsCreate()) throw IOException("Directory doesn't support creation")
+ if (findChild(name) != null) throw FileAlreadyExistsException(name)
// TODO: Handle .tar.gz and such? Is it worth it (will android find them anyway)
val dotIndex = name.lastIndexOf('.')
val mimeType = if (dotIndex > 0) {
@@ -284,9 +287,16 @@ internal open class DocumentDirectory(
val queryArgs = Bundle()
queryArgs.putString(DocumentsContract.QUERY_ARG_DISPLAY_NAME, displayName)
return contentResolver.getAllMetadata(
- DocumentsContract.buildChildDocumentsUriUsingTree(treeUri, metadata.documentId),
+ DocumentsContract.buildChildDocumentsUriUsingTree(
+ treeUri,
+ metadata.documentId
+ ),
queryArgs = queryArgs,
- ).singleOrNull()
+ ).singleOrNull {
+ // Not all document providers use QUERY_ARG_DISPLAY_NAME and the ones
+ // that do can still return partial matches and case insensitive matches
+ it.displayName == displayName
+ }
}
private companion object {