Demote hard name checks to IOExceptions

because it turns out SAF naming things 'null' is a thing
This commit is contained in:
Torsten Grote 2020-10-16 11:23:53 -03:00
parent 2aa3a1b4be
commit f356f56746
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF

View file

@ -178,7 +178,9 @@ internal suspend fun DocumentFile.createOrGetFile(
mimeType: String = MIME_TYPE mimeType: String = MIME_TYPE
): DocumentFile { ): DocumentFile {
return findFileBlocking(context, name) ?: createFile(mimeType, name)?.apply { 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() } ?: throw IOException()
} }
@ -188,7 +190,9 @@ internal suspend fun DocumentFile.createOrGetFile(
@Throws(IOException::class) @Throws(IOException::class)
suspend fun DocumentFile.createOrGetDirectory(context: Context, name: String): DocumentFile { suspend fun DocumentFile.createOrGetDirectory(context: Context, name: String): DocumentFile {
return findFileBlocking(context, name) ?: createDirectory(name)?.apply { 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() } ?: throw IOException()
} }