mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
mkdirs() delete directories if they exist.
This commit is contained in:
parent
ce04dd80d2
commit
6605dd3b99
1 changed files with 6 additions and 5 deletions
|
@ -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!!}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue