skip intermediary copy when filtering jars (#220)

This commit is contained in:
Jason Penilla 2023-11-16 19:54:55 -07:00 committed by GitHub
parent 609bec2f68
commit c7d0820fa1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View file

@ -31,22 +31,20 @@ fun filterJar(
includes: List<String>,
predicate: (Path) -> Boolean = { false }
) {
val target = outputJar.resolveSibling("${outputJar.name}.dir")
target.createDirectories()
ensureDeleted(outputJar)
inputJar.openZip().use { zip ->
val matchers = includes.map { zip.getPathMatcher("glob:$it") }
outputJar.writeZip().use { outputFs ->
inputJar.openZip().use { inputFs ->
val matchers = includes.map { inputFs.getPathMatcher("glob:$it") }
zip.walk().use { stream ->
stream.filter { p -> predicate(p) || matchers.any { matcher -> matcher.matches(p) } }
.forEach { p ->
val targetFile = target.resolve(p.absolutePathString().substring(1))
targetFile.parent.createDirectories()
p.copyTo(targetFile)
}
inputFs.walk().use { stream ->
stream.filter { p -> predicate(p) || matchers.any { matcher -> matcher.matches(p) } }
.forEach { p ->
val targetFile = outputFs.getPath(p.toAbsolutePath().invariantSeparatorsPathString.substring(1))
targetFile.parent?.createDirectories()
p.copyTo(targetFile)
}
}
}
}
zip(target, outputJar)
target.deleteRecursively()
}

View file

@ -64,7 +64,7 @@ class RunPaperclip(
val logFile = outputJar.siblingLogFile()
val work = createTempDirectory()
logFile.deleteForcefully()
ensureDeleted(logFile)
// Copy in mojang jar, so we don't download it twice
val cache = work.resolve("cache")
@ -85,7 +85,7 @@ class RunPaperclip(
handleOldPaperclip(work, outputJar)
}
work.deleteRecursively()
ensureDeleted(work)
}
private fun handleBundler(paperclip: Path, work: Path, outputJar: Path) {