[klib] Finish refactoring of ZipUtil

This commit is contained in:
Sergej Jaskiewicz
2022-12-08 18:47:25 +01:00
committed by Space Team
parent e4d32f3615
commit a66950b629
3 changed files with 6 additions and 21 deletions
@@ -81,8 +81,7 @@ fun <T> File.withZipFileSystem(create: Boolean, action: (FileSystem) -> T): T {
fun <T> File.withZipFileSystem(action: (FileSystem) -> T): T = this.withZipFileSystem(false, action)
// TODO: Make this function private after boostrap advance
fun File.recursiveCopyTo(destination: File, resetTimeAttributes: Boolean = false) {
private fun File.recursiveCopyTo(destination: File, resetTimeAttributes: Boolean = false) {
val sourcePath = javaPath
val destPath = destination.javaPath
val destFs = destPath.fileSystem
@@ -1,9 +1,7 @@
package org.jetbrains.kotlin.library
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.file.file
import org.jetbrains.kotlin.konan.file.recursiveCopyTo
import org.jetbrains.kotlin.konan.file.withZipFileSystem
import org.jetbrains.kotlin.konan.file.unzipTo
import org.jetbrains.kotlin.library.impl.zippedKotlinLibraryChecks
const val KLIB_FILE_EXTENSION = "klib"
@@ -24,10 +22,7 @@ fun File.unpackZippedKonanLibraryTo(newDir: File) {
newDir.delete()
}
// TODO: Replace this with this.unzipTo(newDir) after bootstrap advance
this.withZipFileSystem {
it.file("/").recursiveCopyTo(newDir)
}
this.unzipTo(newDir)
check(newDir.exists) { "Could not unpack $this as $newDir." }
}
@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.library.impl
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.file.file
import org.jetbrains.kotlin.konan.file.unzipTo
import org.jetbrains.kotlin.konan.file.recursiveCopyTo
import org.jetbrains.kotlin.konan.file.withZipFileSystem
import org.jetbrains.kotlin.library.*
import org.jetbrains.kotlin.util.removeSuffixIfPresent
@@ -111,19 +110,11 @@ private fun extract(zipFile: File, file: File) = zipFile.withZipFileSystem { zip
fun KotlinLibraryLayoutImpl.extractDir(directory: File): File = extractDir(this.klib, directory)
// TODO: Use this implementation after bootstrap advance
//private fun extractDir(zipFile: File, directory: File): File {
// val temporary = org.jetbrains.kotlin.konan.file.createTempDir(directory.name)
// temporary.deleteOnExitRecursively()
// zipFile.unzipTo(temporary, fromSubdirectory = directory)
// return temporary
//}
private fun extractDir(zipFile: File, directory: File): File = zipFile.withZipFileSystem { zipFileSystem ->
private fun extractDir(zipFile: File, directory: File): File {
val temporary = org.jetbrains.kotlin.konan.file.createTempDir(directory.name)
zipFileSystem.file(directory).recursiveCopyTo(temporary)
temporary.deleteOnExitRecursively()
temporary
zipFile.unzipTo(temporary, fromSubdirectory = directory)
return temporary
}
open class ExtractingKotlinLibraryLayout(zipped: KotlinLibraryLayoutImpl) : KotlinLibraryLayout {