Selectively uncompress kernel binary from archive (#7)

This commit is contained in:
Aditya Ramani
2025-06-05 15:52:39 -07:00
committed by Kathryn Baldauf
parent f12593c3c2
commit 8a6a593eee
3 changed files with 15 additions and 6 deletions
+13 -3
View File
@@ -77,9 +77,8 @@ actor KernelService {
.setDescription("Unpacking kernel")
])
let archiveReader = try ArchiveReader(file: tarFile)
try archiveReader.extractContents(to: tempDir)
let kernelPath = tempDir.appendingPathComponent(kernelFilePath).resolvingSymlinksInPath()
try self.installKernel(kernelFile: kernelPath, platform: platform)
let kernelFile = try archiveReader.extractFile(from: kernelFilePath, to: tempDir)
try self.installKernel(kernelFile: kernelFile, platform: platform)
if !FileManager.default.fileExists(atPath: tar.absoluteString) {
try FileManager.default.removeItem(at: tarFile)
@@ -108,3 +107,14 @@ actor KernelService {
return Kernel(path: defaultKernelPath, platform: platform)
}
}
extension ArchiveReader {
fileprivate func extractFile(from: String, to directory: URL) throws -> URL {
let (_, data) = try self.extractFile(path: from)
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil)
let fileName = URL(filePath: from).lastPathComponent
let fileURL = directory.appendingPathComponent(fileName)
try data.write(to: fileURL, options: .atomic)
return fileURL
}
}