Clarify the error message when File.copyTo fails (KT-27545)

This commit is contained in:
Abduqodiri Qurbonzoda
2019-08-12 02:15:33 +03:00
parent 27accbb089
commit 11f3c4b03f
@@ -184,15 +184,10 @@ public fun File.copyTo(target: File, overwrite: Boolean = false, bufferSize: Int
}
if (target.exists()) {
val stillExists = if (!overwrite) true else !target.delete()
if (stillExists) {
throw FileAlreadyExistsException(
file = this,
other = target,
reason = "The destination file already exists."
)
}
if (!overwrite)
throw FileAlreadyExistsException(file = this, other = target, reason = "The destination file already exists.")
else if (!target.delete())
throw FileAlreadyExistsException(file = this, other = target, reason = "Tried to overwrite the destination, but failed to delete it.")
}
if (this.isDirectory) {