Clarify the error message when File.copyTo fails (KT-27545)
This commit is contained in:
@@ -184,15 +184,10 @@ public fun File.copyTo(target: File, overwrite: Boolean = false, bufferSize: Int
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (target.exists()) {
|
if (target.exists()) {
|
||||||
val stillExists = if (!overwrite) true else !target.delete()
|
if (!overwrite)
|
||||||
|
throw FileAlreadyExistsException(file = this, other = target, reason = "The destination file already exists.")
|
||||||
if (stillExists) {
|
else if (!target.delete())
|
||||||
throw FileAlreadyExistsException(
|
throw FileAlreadyExistsException(file = this, other = target, reason = "Tried to overwrite the destination, but failed to delete it.")
|
||||||
file = this,
|
|
||||||
other = target,
|
|
||||||
reason = "The destination file already exists."
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isDirectory) {
|
if (this.isDirectory) {
|
||||||
|
|||||||
Reference in New Issue
Block a user