@@ -18,59 +18,6 @@ import Containerization
1818import ContainerizationError
1919import Foundation
2020
21- public struct BundleMetadata : Codable , Sendable {
22- static let bundleMetadataFileName = " bundle-metadata.json "
23-
24- public let path : URL
25- public let initialFilesystem : Filesystem
26- public let kernel : Kernel
27- public let containerConfiguration : ContainerConfiguration ?
28- public let containerRootFilesystem : Filesystem ?
29- public let options : ContainerCreateOptions ?
30-
31- public init (
32- path: URL ,
33- initialFilesystem: Filesystem ,
34- kernel: Kernel ,
35- containerConfiguration: ContainerConfiguration ? = nil ,
36- containerRootFilesystem: Filesystem ? = nil ,
37- options: ContainerCreateOptions ? = nil
38- ) {
39- self . path = path
40- self . initialFilesystem = initialFilesystem
41- self . kernel = kernel
42- self . containerConfiguration = containerConfiguration
43- self . containerRootFilesystem = containerRootFilesystem
44- self . options = options
45- }
46-
47- public var bundleMetadataPath : URL {
48- self . path. appendingPathComponent ( Self . bundleMetadataFileName)
49- }
50-
51- public func writeMetadata( ) throws {
52- // Ensure the parent directory exists
53- let directory = self . bundleMetadataPath. deletingLastPathComponent ( )
54- try FileManager . default. createDirectory ( at: directory, withIntermediateDirectories: true )
55-
56- let data = try JSONEncoder ( ) . encode ( self )
57- try data. write ( to: self . bundleMetadataPath)
58- }
59-
60- public static func readMetadata( from bundlePath: URL ) throws -> BundleMetadata {
61- let metadataPath = bundlePath. appendingPathComponent ( BundleMetadata . bundleMetadataFileName)
62- guard FileManager . default. fileExists ( atPath: metadataPath. path) else {
63- throw ContainerizationError (
64- . notFound,
65- message: " bundle metadata file not found at path: \( metadataPath. path) "
66- )
67- }
68-
69- let data = try Data ( contentsOf: metadataPath)
70- return try JSONDecoder ( ) . decode ( BundleMetadata . self, from: data)
71- }
72- }
73-
7421public struct Bundle : Sendable {
7522 private static let initfsFilename = " initfs.ext4 "
7623 private static let kernelFilename = " kernel.json "
@@ -135,7 +82,9 @@ extension Bundle {
13582 path: URL ,
13683 initialFilesystem: Filesystem ,
13784 kernel: Kernel ,
138- containerConfiguration: ContainerConfiguration ? = nil
85+ containerConfiguration: ContainerConfiguration ? = nil ,
86+ containerRootFilesystem: Filesystem ? = nil ,
87+ options: ContainerCreateOptions ? = nil
13988 ) throws -> Bundle {
14089 try FileManager . default. createDirectory ( at: path, withIntermediateDirectories: true )
14190 let kbin = path. appendingPathComponent ( Self . kernelBinaryFilename)
@@ -160,26 +109,15 @@ extension Bundle {
160109 if let containerConfiguration {
161110 try bundle. write ( filename: Self . containerConfigFilename, value: containerConfiguration)
162111 }
163- return bundle
164- }
165112
166- public static func createFromMetadata( _ metadata: BundleMetadata ) throws -> Bundle {
167- let bundle = try create (
168- path: metadata. path,
169- initialFilesystem: metadata. initialFilesystem,
170- kernel: metadata. kernel,
171- containerConfiguration: metadata. containerConfiguration
172- )
173-
174- if let containerRootFs = metadata. containerRootFilesystem {
175- let readonly = metadata. containerConfiguration? . readOnly ?? false
176- try bundle. setContainerRootFs ( cloning: containerRootFs, readonly: readonly)
113+ if let containerRootFilesystem {
114+ let readonly = containerConfiguration? . readOnly ?? false
115+ try bundle. setContainerRootFs ( cloning: containerRootFilesystem, readonly: readonly)
177116 }
178117
179- if let options = metadata . options {
118+ if let options {
180119 try bundle. write ( filename: " options.json " , value: options)
181120 }
182-
183121 return bundle
184122 }
185123}
0 commit comments