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

Method lookupImageInLocalStorage

libimage/runtime.go:302–378  ·  view source on GitHub ↗

lookupImageInLocalStorage looks up the specified candidate for name in the storage and checks whether it's matching the system context.

(name, candidate string, options *LookupImageOptions)

Source from the content-addressed store, hash-verified

300// lookupImageInLocalStorage looks up the specified candidate for name in the
301// storage and checks whether it's matching the system context.
302func (r *Runtime) lookupImageInLocalStorage(name, candidate string, options *LookupImageOptions) (*Image, error) {
303 logrus.Debugf("Trying %q ...", candidate)
304 img, err := r.store.Image(candidate)
305 if err != nil && errors.Cause(err) != storage.ErrImageUnknown {
306 return nil, err
307 }
308 if img == nil {
309 return nil, nil
310 }
311 ref, err := storageTransport.Transport.ParseStoreReference(r.store, img.ID)
312 if err != nil {
313 return nil, err
314 }
315
316 image := r.storageToImage(img, ref)
317 logrus.Debugf("Found image %q as %q in local containers storage", name, candidate)
318
319 // If we referenced a manifest list, we need to check whether we can
320 // find a matching instance in the local containers storage.
321 isManifestList, err := image.IsManifestList(context.Background())
322 if err != nil {
323 if errors.Cause(err) == os.ErrNotExist {
324 // We must be tolerant toward corrupted images.
325 // See containers/podman commit fd9dd7065d44.
326 logrus.Warnf("Failed to determine if an image is a manifest list: %v, ignoring the error", err)
327 return image, nil
328 }
329 return nil, err
330 }
331 if options.lookupManifest || options.ManifestList {
332 if isManifestList {
333 return image, nil
334 }
335 // return ErrNotAManifestList if lookupManifest is set otherwise try resolving image.
336 if options.lookupManifest {
337 return nil, errors.Wrapf(ErrNotAManifestList, candidate)
338 }
339 }
340
341 if isManifestList {
342 logrus.Debugf("Candidate %q is a manifest list, looking up matching instance", candidate)
343 manifestList, err := image.ToManifestList()
344 if err != nil {
345 return nil, err
346 }
347 instance, err := manifestList.LookupInstance(context.Background(), options.Architecture, options.OS, options.Variant)
348 if err != nil {
349 if options.returnManifestIfNoInstance {
350 logrus.Debug("No matching instance was found: returning manifest list instead")
351 return image, nil
352 }
353 return nil, errors.Wrap(storage.ErrImageUnknown, err.Error())
354 }
355 ref, err = storageTransport.Transport.ParseStoreReference(r.store, "@"+instance.ID())
356 if err != nil {
357 return nil, err
358 }
359 image = instance

Callers 2

LookupImageMethod · 0.95

Calls 7

storageToImageMethod · 0.95
IsManifestListMethod · 0.80
ToManifestListMethod · 0.80
LookupInstanceMethod · 0.80
ErrorMethod · 0.45
IDMethod · 0.45

Tested by

no test coverage detected