KT-45777: Don't include classpath snapshot dir in task output backup

for performance reasons: (1) the snapshots are too big, and (2) they are
usually updated only at the end of the task execution--in a failed task
run, they are usually unchanged and therefore don't need to be restored.
This commit is contained in:
Hung Nguyen
2021-11-19 12:46:11 +03:00
committed by teamcityserver
parent 062a8fe56f
commit 6ba1b2cc08
12 changed files with 137 additions and 74 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.incremental
import java.io.File
import java.io.IOException
fun File.isJavaFile() =
extension.equals("java", ignoreCase = true)
@@ -26,3 +27,43 @@ fun File.isKotlinFile(sourceFilesExtensions: List<String>): Boolean =
fun File.isClassFile(): Boolean =
extension.equals("class", ignoreCase = true)
/**
* Deletes the contents of this directory (not the directory itself) if it exists, or creates the directory if it does not yet exist.
*
* If this is a regular file, this method will throw an exception.
*/
fun File.cleanDirectoryContents() {
when {
isDirectory -> listFiles()!!.forEach { it.forceDeleteRecursively() }
isFile -> error("File.cleanDirectoryContents does not accept a regular file: $path")
else -> forceMkdirs()
}
}
/** Deletes this file or directory recursively (if it exists). */
fun File.forceDeleteRecursively() {
if (!deleteRecursively()) {
throw IOException("Could not delete '$path'")
}
}
/**
* Creates this directory (if it does not yet exist).
*
* If this is a regular file, this method will throw an exception.
*/
@Suppress("SpellCheckingInspection")
fun File.forceMkdirs() {
when {
this.isDirectory -> { /* Do nothing */ }
this.isFile -> error("File.forceMkdirs does not accept a regular file: $path")
else -> {
// Note that if the directory already exists, mkdirs() will return `false`, but here we ensure that the directory does not exist
// before calling mkdirs(), so it's safe to check the returned result of mkdirs() below.
if (!mkdirs()) {
throw IOException("Could not create directory '$path'")
}
}
}
}