From f356f5674670dcb8a9a1c2b9ae129ffc1b80abcd Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 16 Oct 2020 11:23:53 -0300 Subject: [PATCH] Demote hard name checks to IOExceptions because it turns out SAF naming things 'null' is a thing --- .../stevesoltys/seedvault/plugins/saf/DocumentsStorage.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/plugins/saf/DocumentsStorage.kt b/app/src/main/java/com/stevesoltys/seedvault/plugins/saf/DocumentsStorage.kt index 9ad6b2f0..309cc3c9 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/plugins/saf/DocumentsStorage.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/plugins/saf/DocumentsStorage.kt @@ -178,7 +178,9 @@ internal suspend fun DocumentFile.createOrGetFile( mimeType: String = MIME_TYPE ): DocumentFile { return findFileBlocking(context, name) ?: createFile(mimeType, name)?.apply { - check(this.name == name) { "File named ${this.name}, but should be $name" } + if (this.name != name) { + throw IOException("File named ${this.name}, but should be $name") + } } ?: throw IOException() } @@ -188,7 +190,9 @@ internal suspend fun DocumentFile.createOrGetFile( @Throws(IOException::class) suspend fun DocumentFile.createOrGetDirectory(context: Context, name: String): DocumentFile { return findFileBlocking(context, name) ?: createDirectory(name)?.apply { - check(this.name == name) { "Directory named ${this.name}, but should be $name" } + if (this.name != name) { + throw IOException("Directory named ${this.name}, but should be $name") + } } ?: throw IOException() }