Skip to content

Commit

Permalink
Demote hard name checks to IOExceptions
Browse files Browse the repository at this point in the history
because it turns out SAF naming things 'null' is a thing
  • Loading branch information
grote committed Oct 23, 2020
1 parent 2aa3a1b commit f356f56
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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()
}

Expand Down

0 comments on commit f356f56

Please sign in to comment.