1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

mkdirs() delete directories if they exist.

This commit is contained in:
Cedric Beust 2015-11-22 20:57:59 -08:00
parent ce04dd80d2
commit 6605dd3b99

View file

@ -135,12 +135,13 @@ class KFiles {
return result 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 // Need to wait until copyRecursively supports an overwrite: Boolean = false parameter
// Until then, wipe everything first // Until then, wipe everything first
if (deleteFirst) to.deleteRecursively() if (deleteFirst) to.deleteRecursively()
to.mkdirs() // to.mkdirs()
hackCopyRecursively(from, to, replaceExisting) hackCopyRecursively(from, to, replaceExisting, onError)
} }
/** Private exception class, used to terminate recursive copying */ /** Private exception class, used to terminate recursive copying */
@ -217,9 +218,9 @@ class KFiles {
private fun isWindows() = System.getProperty("os.name").contains("Windows"); 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()) { if (isWindows() && to!!.toFile().exists()) {
log(2, "Windows detected, not overwriting ${to!!}") log(2, "Windows detected, not overwriting ${to}")
} else { } else {
try { try {
log(2, "Copy from $from to ${to!!}") log(2, "Copy from $from to ${to!!}")