MCPcopy Create free account
hub / github.com/containers/common / copyFromDefault

Method copyFromDefault

libimage/pull.go:190–265  ·  view source on GitHub ↗

copyFromDefault is the default copier for a number of transports. Other transports require some specific dancing, sometimes Yoga.

(ctx context.Context, ref types.ImageReference, options *CopyOptions)

Source from the content-addressed store, hash-verified

188// copyFromDefault is the default copier for a number of transports. Other
189// transports require some specific dancing, sometimes Yoga.
190func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference, options *CopyOptions) ([]string, error) {
191 c, err := r.newCopier(options)
192 if err != nil {
193 return nil, err
194 }
195 defer c.close()
196
197 // Figure out a name for the storage destination.
198 var storageName, imageName string
199 switch ref.Transport().Name() {
200
201 case dockerDaemonTransport.Transport.Name():
202 // Normalize to docker.io if needed (see containers/podman/issues/10998).
203 named, err := reference.ParseNormalizedNamed(ref.StringWithinTransport())
204 if err != nil {
205 return nil, err
206 }
207 imageName = named.String()
208 storageName = imageName
209
210 case ociTransport.Transport.Name():
211 split := strings.SplitN(ref.StringWithinTransport(), ":", 2)
212 storageName = toLocalImageName(split[0])
213 imageName = storageName
214
215 case ociArchiveTransport.Transport.Name():
216 manifestDescriptor, err := ociArchiveTransport.LoadManifestDescriptor(ref)
217 if err != nil {
218 return nil, err
219 }
220 storageName = nameFromAnnotations(manifestDescriptor.Annotations)
221 switch len(storageName) {
222 case 0:
223 // If there's no reference name in the annotations, compute an ID.
224 storageName, err = getImageID(ctx, ref, nil)
225 if err != nil {
226 return nil, err
227 }
228 imageName = "sha256:" + storageName[1:]
229 default:
230 named, err := NormalizeName(storageName)
231 if err != nil {
232 return nil, err
233 }
234 imageName = named.String()
235 storageName = imageName
236 }
237
238 case storageTransport.Transport.Name():
239 storageName = ref.StringWithinTransport()
240 named := ref.DockerReference()
241 if named == nil {
242 return nil, errors.Errorf("could not get an image name for storage reference %q", ref)
243 }
244 imageName = named.String()
245
246 default:
247 // Path-based transports (e.g., dir) may include invalid

Callers 2

PullMethod · 0.95
LoadMethod · 0.95

Calls 8

newCopierMethod · 0.95
toLocalImageNameFunction · 0.85
nameFromAnnotationsFunction · 0.85
getImageIDFunction · 0.85
NormalizeNameFunction · 0.85
closeMethod · 0.80
copyMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected