From 6605dd3b99e2c06996b54e7227a3fad1a3a965e0 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 22 Nov 2015 20:57:59 -0800 Subject: [PATCH] mkdirs() delete directories if they exist. --- src/main/kotlin/com/beust/kobalt/misc/KFiles.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 2a66a816..e11be3c6 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -135,12 +135,13 @@ class KFiles { return result } - fun copyRecursively(from: File, to: File, replaceExisting: Boolean = true, deleteFirst: Boolean = true) { + fun copyRecursively(from: File, to: File, replaceExisting: Boolean = true, deleteFirst: Boolean = true, + onError: (File, IOException) -> OnErrorAction = { file, exception -> throw exception }) { // Need to wait until copyRecursively supports an overwrite: Boolean = false parameter // Until then, wipe everything first if (deleteFirst) to.deleteRecursively() - to.mkdirs() - hackCopyRecursively(from, to, replaceExisting) +// to.mkdirs() + hackCopyRecursively(from, to, replaceExisting, onError) } /** Private exception class, used to terminate recursive copying */ @@ -217,9 +218,9 @@ class KFiles { private fun isWindows() = System.getProperty("os.name").contains("Windows"); - fun copy(from: Path?, to: Path?, option: StandardCopyOption) { + fun copy(from: Path?, to: Path?, option: StandardCopyOption = StandardCopyOption.REPLACE_EXISTING) { if (isWindows() && to!!.toFile().exists()) { - log(2, "Windows detected, not overwriting ${to!!}") + log(2, "Windows detected, not overwriting ${to}") } else { try { log(2, "Copy from $from to ${to!!}")