mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Finish --gc.
This commit is contained in:
parent
7a0ead0eac
commit
8ca320bedc
2 changed files with 20 additions and 30 deletions
|
@ -45,12 +45,22 @@ class Io(val dryRun: Boolean = false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rmDir(dir: File) {
|
fun rmDir(dir: File, keep: (File) -> Boolean = { t -> false }) = rmDir(dir, keep, " ")
|
||||||
|
|
||||||
|
private fun rmDir(dir: File, keep: (File) -> Boolean, indent : String) {
|
||||||
log("rm -rf $dir")
|
log("rm -rf $dir")
|
||||||
|
|
||||||
if (! dryRun) {
|
|
||||||
require(dir.isDirectory, { -> println("$dir should be a directory")})
|
require(dir.isDirectory, { -> println("$dir should be a directory")})
|
||||||
dir.deleteRecursively()
|
|
||||||
|
dir.listFiles({ p0 -> ! keep(p0!!) }).forEach {
|
||||||
|
if (it.isDirectory) {
|
||||||
|
rmDir(it, keep, indent + " ")
|
||||||
|
it.deleteRecursively()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log(indent + "rm $it")
|
||||||
|
if (! dryRun) it.delete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,38 +4,18 @@ import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.misc.Io
|
import com.beust.kobalt.misc.Io
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up old Kobalt files.
|
* Clean up old Kobalt files.
|
||||||
*/
|
*/
|
||||||
class Gc {
|
class Gc {
|
||||||
fun run() {
|
fun run() {
|
||||||
// Delete all the distributions except the current one
|
val io = Io(dryRun = false)
|
||||||
val dist = KFiles.distributionsDir
|
|
||||||
|
// Delete all the files that don't have kobalt-$version in them
|
||||||
val version = Kobalt.version
|
val version = Kobalt.version
|
||||||
val tmpDir = Files.createTempDirectory("kobalt")
|
val name = "kobalt-$version"
|
||||||
|
val dist = File(KFiles.distributionsDir)
|
||||||
// Zipfile
|
io.rmDir(dist) { f: File -> f.absolutePath.contains(name) }
|
||||||
val io = Io(dryRun = true)
|
|
||||||
val zipFileName = "kobalt-$version.zip"
|
|
||||||
io.moveFile(File(KFiles.joinDir(dist, zipFileName)), tmpDir.toFile())
|
|
||||||
|
|
||||||
// Distribution directory
|
|
||||||
val zipDirectoryName = "kobalt-$version"
|
|
||||||
val zipDirectory = File(KFiles.joinDir(dist, zipDirectoryName))
|
|
||||||
io.copyDirectory(zipDirectory, tmpDir.toFile())
|
|
||||||
|
|
||||||
// Delete the whole dist directory and recreate it
|
|
||||||
File(dist).let { distFile ->
|
|
||||||
io.rmDir(distFile)
|
|
||||||
io.mkdir(distFile)
|
|
||||||
|
|
||||||
// Copy the files back
|
|
||||||
tmpDir.toFile().absolutePath.let { fromPath ->
|
|
||||||
io.moveFile(File(KFiles.joinDir(fromPath, zipFileName)), distFile)
|
|
||||||
io.copyDirectory(File(KFiles.joinDir(fromPath, zipDirectoryName)), distFile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue