1414// limitations under the License.
1515//===----------------------------------------------------------------------===//
1616
17- //
18- 
1917import  ContainerizationError
2018import  ContainerizationExtras
2119import  ContainerizationOCI
@@ -40,7 +38,7 @@ extension ImageStore {
4038        } 
4139
4240        /// Pull the required image layers for the provided descriptor and platform(s) into the given directory using the provided client. Returns a descriptor to the Index manifest.
43-         internal  func  `import`( root:  Descriptor ,  matcher:  ( ContainerizationOCI . Platform )  ->  Bool )  async  throws  ->  Descriptor  { 
41+         internal  func  `import`( root:  OCIDescriptor ,  matcher:  ( OCIPlatform )  ->  Bool )  async  throws  ->  OCIDescriptor  { 
4442            var  toProcess  =  [ root] 
4543            while  !toProcess. isEmpty { 
4644                // Count the total number of blobs and their size
@@ -61,14 +59,14 @@ extension ImageStore {
6159                toProcess =  filtered. uniqued  {  $0. digest } 
6260            } 
6361
64-             guard  root. mediaType !=  MediaTypes . dockerManifestList && root. mediaType !=  MediaTypes . index else  { 
62+             guard  root. mediaType !=  OCIMediaTypes . dockerManifestList && root. mediaType !=  OCIMediaTypes . index else  { 
6563                return  root
6664            } 
6765
6866            // Create an index for the root descriptor and write it to the content store
6967            let  index  =  try await  self . createIndex ( for:  root) 
70-             // In cases where the root descriptor pointed to `MediaTypes .imageManifest`
71-             // Or `MediaTypes .dockerManifest`, it is required that we check the supported platform
68+             // In cases where the root descriptor pointed to `OCIMediaTypes .imageManifest`
69+             // Or `OCIMediaTypes .dockerManifest`, it is required that we check the supported platform
7270            // matches the platforms we were asked to pull. This can be done only after we created
7371            // the Index.
7472            let  supportedPlatforms  =  index. manifests. compactMap  {  $0. platform } 
@@ -77,13 +75,13 @@ extension ImageStore {
7775            } 
7876            let  writer  =  try ContentWriter ( for:  self . ingestDir) 
7977            let  result  =  try . create ( from:  index) 
80-             return  Descriptor ( 
81-                 mediaType:  MediaTypes . index, 
78+             return  OCIDescriptor ( 
79+                 mediaType:  OCIMediaTypes . index, 
8280                digest:  result. digest. digestString, 
8381                size:  Int64 ( result. size) ) 
8482        } 
8583
86-         private  func  getManifestContent< T:  Sendable  &  Codable > ( descriptor:  Descriptor )  async  throws  ->  T  { 
84+         private  func  getManifestContent< T:  Sendable  &  Codable > ( descriptor:  OCIDescriptor )  async  throws  ->  T  { 
8785            do  { 
8886                if let  content =  try await  self . contentStore. get ( digest:  descriptor. digest. trimmingDigestPrefix)  { 
8987                    return  try . decode ( ) 
@@ -97,16 +95,16 @@ extension ImageStore {
9795            } 
9896        } 
9997
100-         private func  walk( _ descriptors:  [ Descriptor ] )  async  throws ->  [ Descriptor ]  { 
101-             var  out :  [ Descriptor ]  =  [ ] 
98+         private func  walk( _ descriptors:  [ OCIDescriptor ] )  async  throws ->  [ OCIDescriptor ]  { 
99+             var  out :  [ OCIDescriptor ]  =  [ ] 
102100            for  desc  in  descriptors { 
103101                let  mediaType  =  desc. mediaType
104102                switch  mediaType { 
105-                 case  MediaTypes . index,  MediaTypes . dockerManifestList: 
106-                     let  index :  Index  =  try await  self . getManifestContent ( descriptor:  desc) 
103+                 case  OCIMediaTypes . index,  OCIMediaTypes . dockerManifestList: 
104+                     let  index :  OCIIndex  =  try await  self . getManifestContent ( descriptor:  desc) 
107105                    out. append ( contentsOf:  index. manifests) 
108-                 case  MediaTypes . imageManifest,  MediaTypes . dockerManifest: 
109-                     let  manifest :  Manifest  =  try await  self . getManifestContent ( descriptor:  desc) 
106+                 case  OCIMediaTypes . imageManifest,  OCIMediaTypes . dockerManifest: 
107+                     let  manifest :  OCIManifest  =  try await  self . getManifestContent ( descriptor:  desc) 
110108                    out. append ( manifest. config) 
111109                    out. append ( contentsOf:  manifest. layers) 
112110                default : 
@@ -117,7 +115,7 @@ extension ImageStore {
117115            return  out
118116        } 
119117
120-         private func fetchAll( _ descriptors:  [ Descriptor ] )  async  throws { 
118+         private func fetchAll( _ descriptors:  [ OCIDescriptor ] )  async  throws { 
121119            try await  withThrowingTaskGroup ( of:  Void . self)  {  group in 
122120                var  iterator  =  descriptors. makeIterator ( ) 
123121                for  _  in  0 ..< 8  { 
@@ -137,7 +135,7 @@ extension ImageStore {
137135            } 
138136        } 
139137
140-         private func fetch( _ descriptor:  Descriptor )  async  throws { 
138+         private func fetch( _ descriptor:  OCIDescriptor )  async  throws { 
141139            if  let  found =  try await  self . contentStore. get ( digest:  descriptor. digest)  { 
142140                try FileManager . default. copyItem ( at:  found. path,  to:  ingestDir. appendingPathComponent ( descriptor. digest. trimmingDigestPrefix) ) 
143141                await  progress ? ( [ 
@@ -160,7 +158,7 @@ extension ImageStore {
160158            ] ) 
161159        } 
162160
163-         private func fetchBlob( _ descriptor:  Descriptor )  async  throws { 
161+         private func fetchBlob( _ descriptor:  OCIDescriptor )  async  throws { 
164162            let  id  =  UUID ( ) . uuidString
165163            let  fm  =  FileManager . default
166164            let  tempFile  =  ingestDir. appendingPathComponent ( id) 
@@ -179,7 +177,7 @@ extension ImageStore {
179177        } 
180178
181179        @discardableResult
182-         private func  fetchData( _ descriptor:  Descriptor )  async  throws ->  Data { 
180+         private func  fetchData( _ descriptor:  OCIDescriptor )  async  throws ->  Data { 
183181            let  data  =  try await  client. fetchData ( name:  name,  descriptor:  descriptor) 
184182            let  writer  =  try ContentWriter ( for:  ingestDir) 
185183            let  result  =  try . write ( data) 
@@ -195,11 +193,11 @@ extension ImageStore {
195193            return  data
196194        } 
197195
198-         private func createIndex( for root:  Descriptor )  async  throws ->  Index  { 
196+         private func createIndex( for root:  OCIDescriptor )  async  throws ->  OCIIndex  { 
199197            switch  root. mediaType { 
200-             case  MediaTypes . index,  MediaTypes . dockerManifestList: 
198+             case  OCIMediaTypes . index,  OCIMediaTypes . dockerManifestList: 
201199                return  try await  self . getManifestContent ( descriptor:  root) 
202-             case  MediaTypes . imageManifest,  MediaTypes . dockerManifest: 
200+             case  OCIMediaTypes . imageManifest,  OCIMediaTypes . dockerManifest: 
203201                let  supportedPlatforms  =  try await  getSupportedPlatforms ( for:  root) 
204202                guard  supportedPlatforms. count ==  1  else  { 
205203                    throw  ContainerizationError ( 
@@ -211,20 +209,20 @@ extension ImageStore {
211209                let  platform  =  supportedPlatforms. first!
212210                var  root  =  root
213211                root. platform =  platform
214-                 let  index  =  ContainerizationOCI . Index ( 
212+                 let  index  =  OCIIndex ( 
215213                    schemaVersion:  2 ,  manifests:  [ root] , 
216214                    annotations:  [ 
217215                        // indicate that this is a synthesized index which is not directly user facing
218-                         AnnotationKeys . containerizationIndexIndirect:  " true " 
216+                         OCIAnnotationKeys . containerizationIndexIndirect:  " true " 
219217                    ] ) 
220218                return  index
221219            default : 
222220                throw  ContainerizationError ( . internalError,  message:  " Failed to create index for descriptor  \( root. digest) , media type  \( root. mediaType) " ) 
223221            } 
224222        } 
225223
226-         private func getSupportedPlatforms( for root:  Descriptor )  async  throws ->  [ ContainerizationOCI . Platform ]  { 
227-             var  supportedPlatforms :  [ ContainerizationOCI . Platform ]  =  [ ] 
224+         private func getSupportedPlatforms( for root:  OCIDescriptor )  async  throws ->  [ OCIPlatform ]  { 
225+             var  supportedPlatforms :  [ OCIPlatform ]  =  [ ] 
228226            var  toProcess  =  [ root] 
229227            while  !toProcess. isEmpty { 
230228                let  children  =  try await  self . walk ( toProcess) 
@@ -234,9 +232,9 @@ extension ImageStore {
234232                        continue 
235233                    } 
236234                    switch  child. mediaType { 
237-                     case  MediaTypes . imageConfig,  MediaTypes . dockerImageConfig: 
238-                         let  config :  ContainerizationOCI . Image  =  try await  self . getManifestContent ( descriptor:  child) 
239-                         let  p  =  ContainerizationOCI . Platform ( 
235+                     case  OCIMediaTypes . imageConfig,  OCIMediaTypes . dockerImageConfig: 
236+                         let  config :  OCIImage  =  try await  self . getManifestContent ( descriptor:  child) 
237+                         let  p  =  OCIPlatform ( 
240238                            arch:  config. architecture,  os:  config. os,  osFeatures:  config. osFeatures,  variant:  config. variant
241239                        ) 
242240                        supportedPlatforms. append ( p) 
0 commit comments