newImageSource sets up an image for reading.
(sys *types.SystemContext, imageRef storageReference)
| 61 | |
| 62 | // newImageSource sets up an image for reading. |
| 63 | func newImageSource(sys *types.SystemContext, imageRef storageReference) (*storageImageSource, error) { |
| 64 | // First, locate the image. |
| 65 | img, err := imageRef.resolveImage(sys) |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | |
| 70 | // Build the reader object. |
| 71 | image := &storageImageSource{ |
| 72 | PropertyMethodsInitialize: impl.PropertyMethods(impl.Properties{ |
| 73 | HasThreadSafeGetBlob: true, |
| 74 | }), |
| 75 | NoGetBlobAtInitialize: stubs.NoGetBlobAt(imageRef), |
| 76 | |
| 77 | imageRef: imageRef, |
| 78 | systemContext: sys, |
| 79 | image: img, |
| 80 | metadata: storageImageMetadata{ |
| 81 | SignatureSizes: []int{}, |
| 82 | SignaturesSizes: make(map[digest.Digest][]int), |
| 83 | }, |
| 84 | getBlobMutexProtected: getBlobMutexProtected{ |
| 85 | digestToLayerID: make(map[digest.Digest]string), |
| 86 | layerPosition: make(map[digest.Digest]int), |
| 87 | }, |
| 88 | } |
| 89 | image.Compat = impl.AddCompat(image) |
| 90 | if img.Metadata != "" { |
| 91 | if err := json.Unmarshal([]byte(img.Metadata), &image.metadata); err != nil { |
| 92 | return nil, fmt.Errorf("decoding metadata for source image: %w", err) |
| 93 | } |
| 94 | } |
| 95 | return image, nil |
| 96 | } |
| 97 | |
| 98 | // Reference returns the image reference that we used to find this image. |
| 99 | func (s *storageImageSource) Reference() types.ImageReference { |
no test coverage detected
searching dependent graphs…