mirror of
				https://github.com/containers/podman.git
				synced 2025-11-04 08:56:05 +08:00 
			
		
		
		
	vendor latest c/common main
Includes several rootless-netns fixes. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
		
							
								
								
									
										37
									
								
								vendor/github.com/containers/common/libimage/load.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										37
									
								
								vendor/github.com/containers/common/libimage/load.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@ -13,6 +13,7 @@ import (
 | 
			
		||||
	dockerArchiveTransport "github.com/containers/image/v5/docker/archive"
 | 
			
		||||
	ociArchiveTransport "github.com/containers/image/v5/oci/archive"
 | 
			
		||||
	ociTransport "github.com/containers/image/v5/oci/layout"
 | 
			
		||||
	"github.com/containers/image/v5/transports"
 | 
			
		||||
	"github.com/containers/image/v5/types"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
@ -21,6 +22,30 @@ type LoadOptions struct {
 | 
			
		||||
	CopyOptions
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// doLoadReference does the heavy lifting for LoadReference() and Load(),
 | 
			
		||||
// without adding debug messages or handling defaults.
 | 
			
		||||
func (r *Runtime) doLoadReference(ctx context.Context, ref types.ImageReference, options *LoadOptions) (images []string, transportName string, err error) {
 | 
			
		||||
	transportName = ref.Transport().Name()
 | 
			
		||||
	switch transportName {
 | 
			
		||||
	case dockerArchiveTransport.Transport.Name():
 | 
			
		||||
		images, err = r.loadMultiImageDockerArchive(ctx, ref, &options.CopyOptions)
 | 
			
		||||
	default:
 | 
			
		||||
		images, err = r.copyFromDefault(ctx, ref, &options.CopyOptions)
 | 
			
		||||
	}
 | 
			
		||||
	return images, ref.Transport().Name(), err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LoadReference loads one or more images from the specified location.
 | 
			
		||||
func (r *Runtime) LoadReference(ctx context.Context, ref types.ImageReference, options *LoadOptions) ([]string, error) {
 | 
			
		||||
	logrus.Debugf("Loading image from %q", transports.ImageName(ref))
 | 
			
		||||
 | 
			
		||||
	if options == nil {
 | 
			
		||||
		options = &LoadOptions{}
 | 
			
		||||
	}
 | 
			
		||||
	images, _, err := r.doLoadReference(ctx, ref, options)
 | 
			
		||||
	return images, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Load loads one or more images (depending on the transport) from the
 | 
			
		||||
// specified path.  The path may point to an image the following transports:
 | 
			
		||||
// oci, oci-archive, dir, docker-archive.
 | 
			
		||||
@ -41,8 +66,7 @@ func (r *Runtime) Load(ctx context.Context, path string, options *LoadOptions) (
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, ociTransport.Transport.Name(), err
 | 
			
		||||
			}
 | 
			
		||||
			images, err := r.copyFromDefault(ctx, ref, &options.CopyOptions)
 | 
			
		||||
			return images, ociTransport.Transport.Name(), err
 | 
			
		||||
			return r.doLoadReference(ctx, ref, options)
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		// OCI-ARCHIVE
 | 
			
		||||
@ -52,8 +76,7 @@ func (r *Runtime) Load(ctx context.Context, path string, options *LoadOptions) (
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, ociArchiveTransport.Transport.Name(), err
 | 
			
		||||
			}
 | 
			
		||||
			images, err := r.copyFromDefault(ctx, ref, &options.CopyOptions)
 | 
			
		||||
			return images, ociArchiveTransport.Transport.Name(), err
 | 
			
		||||
			return r.doLoadReference(ctx, ref, options)
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		// DOCKER-ARCHIVE
 | 
			
		||||
@ -63,8 +86,7 @@ func (r *Runtime) Load(ctx context.Context, path string, options *LoadOptions) (
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, dockerArchiveTransport.Transport.Name(), err
 | 
			
		||||
			}
 | 
			
		||||
			images, err := r.loadMultiImageDockerArchive(ctx, ref, &options.CopyOptions)
 | 
			
		||||
			return images, dockerArchiveTransport.Transport.Name(), err
 | 
			
		||||
			return r.doLoadReference(ctx, ref, options)
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		// DIR
 | 
			
		||||
@ -74,8 +96,7 @@ func (r *Runtime) Load(ctx context.Context, path string, options *LoadOptions) (
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, dirTransport.Transport.Name(), err
 | 
			
		||||
			}
 | 
			
		||||
			images, err := r.copyFromDefault(ctx, ref, &options.CopyOptions)
 | 
			
		||||
			return images, dirTransport.Transport.Name(), err
 | 
			
		||||
			return r.doLoadReference(ctx, ref, options)
 | 
			
		||||
		},
 | 
			
		||||
	} {
 | 
			
		||||
		loadedImages, transportName, err := f()
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										55
									
								
								vendor/github.com/containers/common/libimage/manifest_list.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										55
									
								
								vendor/github.com/containers/common/libimage/manifest_list.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@ -314,6 +314,29 @@ type ManifestListAddOptions struct {
 | 
			
		||||
	Password string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *ManifestList) parseNameToExtantReference(ctx context.Context, name string, manifestList bool, what string) (types.ImageReference, error) {
 | 
			
		||||
	ref, err := alltransports.ParseImageName(name)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		withDocker := fmt.Sprintf("%s://%s", docker.Transport.Name(), name)
 | 
			
		||||
		ref, err = alltransports.ParseImageName(withDocker)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			var src types.ImageSource
 | 
			
		||||
			src, err = ref.NewImageSource(ctx, nil)
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				src.Close()
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			image, _, lookupErr := m.image.runtime.LookupImage(name, &LookupImageOptions{ManifestList: manifestList})
 | 
			
		||||
			if lookupErr != nil {
 | 
			
		||||
				return nil, fmt.Errorf("locating %s: %q: %w; %q: %w", what, withDocker, err, name, lookupErr)
 | 
			
		||||
			}
 | 
			
		||||
			ref, err = image.storageReference, nil
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return ref, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Add adds one or more manifests to the manifest list and returns the digest
 | 
			
		||||
// of the added instance.
 | 
			
		||||
func (m *ManifestList) Add(ctx context.Context, name string, options *ManifestListAddOptions) (digest.Digest, error) {
 | 
			
		||||
@ -321,13 +344,9 @@ func (m *ManifestList) Add(ctx context.Context, name string, options *ManifestLi
 | 
			
		||||
		options = &ManifestListAddOptions{}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ref, err := alltransports.ParseImageName(name)
 | 
			
		||||
	ref, err := m.parseNameToExtantReference(ctx, name, false, "image to add to manifest list")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		withDocker := fmt.Sprintf("%s://%s", docker.Transport.Name(), name)
 | 
			
		||||
		ref, err = alltransports.ParseImageName(withDocker)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Now massage in the copy-related options into the system context.
 | 
			
		||||
@ -428,17 +447,9 @@ func (m *ManifestList) AddArtifact(ctx context.Context, options *ManifestListAdd
 | 
			
		||||
		opts.LayerMediaType = &options.LayerType
 | 
			
		||||
	}
 | 
			
		||||
	if options.Subject != "" {
 | 
			
		||||
		ref, err := alltransports.ParseImageName(options.Subject)
 | 
			
		||||
		ref, err := m.parseNameToExtantReference(ctx, options.Subject, true, "subject for artifact manifest")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			withDocker := fmt.Sprintf("%s://%s", docker.Transport.Name(), options.Subject)
 | 
			
		||||
			ref, err = alltransports.ParseImageName(withDocker)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				image, _, err := m.image.runtime.LookupImage(options.Subject, &LookupImageOptions{ManifestList: true})
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return "", fmt.Errorf("locating subject for artifact manifest: %w", err)
 | 
			
		||||
				}
 | 
			
		||||
				ref = image.storageReference
 | 
			
		||||
			}
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
		opts.SubjectReference = ref
 | 
			
		||||
	}
 | 
			
		||||
@ -541,17 +552,9 @@ func (m *ManifestList) AnnotateInstance(d digest.Digest, options *ManifestListAn
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if options.Subject != "" {
 | 
			
		||||
		ref, err := alltransports.ParseImageName(options.Subject)
 | 
			
		||||
		ref, err := m.parseNameToExtantReference(ctx, options.Subject, true, "subject for image index")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			withDocker := fmt.Sprintf("%s://%s", docker.Transport.Name(), options.Subject)
 | 
			
		||||
			ref, err = alltransports.ParseImageName(withDocker)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				image, _, err := m.image.runtime.LookupImage(options.Subject, &LookupImageOptions{ManifestList: true})
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return fmt.Errorf("locating subject for image index: %w", err)
 | 
			
		||||
				}
 | 
			
		||||
				ref = image.storageReference
 | 
			
		||||
			}
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		src, err := ref.NewImageSource(ctx, &m.image.runtime.systemContext)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								vendor/github.com/containers/common/libimage/manifests/manifests.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								vendor/github.com/containers/common/libimage/manifests/manifests.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@ -495,6 +495,14 @@ func prepareAddWithCompression(variants []string) ([]cp.OptionCompressionVariant
 | 
			
		||||
	return res, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func mapToSlice(m map[string]string) []string {
 | 
			
		||||
	slice := make([]string, 0, len(m))
 | 
			
		||||
	for key, value := range m {
 | 
			
		||||
		slice = append(slice, key+"="+value)
 | 
			
		||||
	}
 | 
			
		||||
	return slice
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Add adds information about the specified image to the list, computing the
 | 
			
		||||
// image's manifest's digest, retrieving OS and architecture information from
 | 
			
		||||
// the image's configuration, and recording the image's reference so that it
 | 
			
		||||
@ -516,6 +524,7 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag
 | 
			
		||||
		Size                                 int64
 | 
			
		||||
		ConfigInfo                           types.BlobInfo
 | 
			
		||||
		ArtifactType                         string
 | 
			
		||||
		URLs                                 []string
 | 
			
		||||
	}
 | 
			
		||||
	var instanceInfos []instanceInfo
 | 
			
		||||
	var manifestDigest digest.Digest
 | 
			
		||||
@ -547,6 +556,8 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag
 | 
			
		||||
					OSFeatures:     append([]string{}, platform.OSFeatures...),
 | 
			
		||||
					Size:           instance.Size,
 | 
			
		||||
					ArtifactType:   instance.ArtifactType,
 | 
			
		||||
					Annotations:    mapToSlice(instance.Annotations),
 | 
			
		||||
					URLs:           instance.URLs,
 | 
			
		||||
				}
 | 
			
		||||
				instanceInfos = append(instanceInfos, instanceInfo)
 | 
			
		||||
			}
 | 
			
		||||
@ -578,6 +589,8 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag
 | 
			
		||||
					OSFeatures:     append([]string{}, platform.OSFeatures...),
 | 
			
		||||
					Size:           instance.Size,
 | 
			
		||||
					ArtifactType:   instance.ArtifactType,
 | 
			
		||||
					Annotations:    mapToSlice(instance.Annotations),
 | 
			
		||||
					URLs:           instance.URLs,
 | 
			
		||||
				}
 | 
			
		||||
				instanceInfos = append(instanceInfos, instanceInfo)
 | 
			
		||||
				added = true
 | 
			
		||||
@ -649,6 +662,9 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", fmt.Errorf("adding instance with digest %q: %w", *instanceInfo.instanceDigest, err)
 | 
			
		||||
		}
 | 
			
		||||
		if err = l.List.SetURLs(*instanceInfo.instanceDigest, instanceInfo.URLs); err != nil {
 | 
			
		||||
			return "", fmt.Errorf("setting URLs for instance with digest %q: %w", *instanceInfo.instanceDigest, err)
 | 
			
		||||
		}
 | 
			
		||||
		if _, ok := l.instances[*instanceInfo.instanceDigest]; !ok {
 | 
			
		||||
			l.instances[*instanceInfo.instanceDigest] = transports.ImageName(ref)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								vendor/github.com/containers/common/libimage/pull.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/containers/common/libimage/pull.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@ -240,6 +240,15 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
 | 
			
		||||
	// Figure out a name for the storage destination.
 | 
			
		||||
	var storageName, imageName string
 | 
			
		||||
	switch ref.Transport().Name() {
 | 
			
		||||
	case registryTransport.Transport.Name():
 | 
			
		||||
		// Normalize to docker.io if needed (see containers/podman/issues/10998).
 | 
			
		||||
		named, err := reference.ParseNormalizedNamed(strings.TrimLeft(ref.StringWithinTransport(), ":/"))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		imageName = named.String()
 | 
			
		||||
		storageName = imageName
 | 
			
		||||
 | 
			
		||||
	case dockerDaemonTransport.Transport.Name():
 | 
			
		||||
		// Normalize to docker.io if needed (see containers/podman/issues/10998).
 | 
			
		||||
		named, err := reference.ParseNormalizedNamed(ref.StringWithinTransport())
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user