mirror of
https://github.com/containers/podman.git
synced 2025-12-02 19:28:58 +08:00
Vendor c/common:8483ef6022b4
This commit vendor pre-release version of `c/common:8483ef6022b4`. It also adapts the code to the new `c/common/libimage` API, which fixes an image listing race that was listing false warnings. fixes: #23331 Signed-off-by: Jan Rodák <hony.com@seznam.cz>
This commit is contained in:
92
vendor/github.com/containers/common/libimage/runtime.go
generated
vendored
92
vendor/github.com/containers/common/libimage/runtime.go
generated
vendored
@@ -161,6 +161,23 @@ func (r *Runtime) storageToImage(storageImage *storage.Image, ref types.ImageRef
|
||||
}
|
||||
}
|
||||
|
||||
// getImagesAndLayers obtains consistent slices of Image and storage.Layer
|
||||
func (r *Runtime) getImagesAndLayers() ([]*Image, []storage.Layer, error) {
|
||||
snapshot, err := r.store.MultiList(
|
||||
storage.MultiListOptions{
|
||||
Images: true,
|
||||
Layers: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
images := []*Image{}
|
||||
for i := range snapshot.Images {
|
||||
images = append(images, r.storageToImage(&snapshot.Images[i], nil))
|
||||
}
|
||||
return images, snapshot.Layers, nil
|
||||
}
|
||||
|
||||
// Exists returns true if the specified image exists in the local containers
|
||||
// storage. Note that it may return false if an image corrupted.
|
||||
func (r *Runtime) Exists(name string) (bool, error) {
|
||||
@@ -479,7 +496,7 @@ func (r *Runtime) lookupImageInDigestsAndRepoTags(name string, possiblyUnqualifi
|
||||
return nil, "", fmt.Errorf("%s: %w (could not cast to tagged)", originalName, storage.ErrImageUnknown)
|
||||
}
|
||||
|
||||
allImages, err := r.ListImages(context.Background(), nil, nil)
|
||||
allImages, err := r.ListImages(context.Background(), nil)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -567,39 +584,46 @@ type ListImagesOptions struct {
|
||||
SetListData bool
|
||||
}
|
||||
|
||||
// ListImages lists images in the local container storage. If names are
|
||||
// specified, only images with the specified names are looked up and filtered.
|
||||
func (r *Runtime) ListImages(ctx context.Context, names []string, options *ListImagesOptions) ([]*Image, error) {
|
||||
// ListImagesByNames lists the images in the local container storage by specified names
|
||||
// The name lookups use the LookupImage semantics.
|
||||
func (r *Runtime) ListImagesByNames(names []string) ([]*Image, error) {
|
||||
images := []*Image{}
|
||||
for _, name := range names {
|
||||
image, _, err := r.LookupImage(name, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
images = append(images, image)
|
||||
}
|
||||
return images, nil
|
||||
}
|
||||
|
||||
// ListImages lists the images in the local container storage and filter the images by ListImagesOptions
|
||||
func (r *Runtime) ListImages(ctx context.Context, options *ListImagesOptions) ([]*Image, error) {
|
||||
if options == nil {
|
||||
options = &ListImagesOptions{}
|
||||
}
|
||||
|
||||
var images []*Image
|
||||
if len(names) > 0 {
|
||||
for _, name := range names {
|
||||
image, _, err := r.LookupImage(name, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
images = append(images, image)
|
||||
}
|
||||
} else {
|
||||
storageImages, err := r.store.Images()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range storageImages {
|
||||
images = append(images, r.storageToImage(&storageImages[i], nil))
|
||||
}
|
||||
}
|
||||
|
||||
filtered, err := r.filterImages(ctx, images, options)
|
||||
filters, needsLayerTree, err := r.compileImageFilters(ctx, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !options.SetListData {
|
||||
return filtered, nil
|
||||
if options.SetListData {
|
||||
needsLayerTree = true
|
||||
}
|
||||
|
||||
snapshot, err := r.store.MultiList(
|
||||
storage.MultiListOptions{
|
||||
Images: true,
|
||||
Layers: needsLayerTree,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
images := []*Image{}
|
||||
for i := range snapshot.Images {
|
||||
images = append(images, r.storageToImage(&snapshot.Images[i], nil))
|
||||
}
|
||||
|
||||
// If explicitly requested by the user, pre-compute and cache the
|
||||
@@ -608,11 +632,23 @@ func (r *Runtime) ListImages(ctx context.Context, names []string, options *ListI
|
||||
// as the layer tree will computed once for all instead of once for
|
||||
// each individual image (see containers/podman/issues/17828).
|
||||
|
||||
tree, err := r.layerTree(ctx, images)
|
||||
var tree *layerTree
|
||||
if needsLayerTree {
|
||||
tree, err = r.newLayerTreeFromData(images, snapshot.Layers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
filtered, err := r.filterImages(ctx, images, filters, tree)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !options.SetListData {
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
for i := range filtered {
|
||||
isDangling, err := filtered[i].isDangling(ctx, tree)
|
||||
if err != nil {
|
||||
@@ -753,7 +789,7 @@ func (r *Runtime) RemoveImages(ctx context.Context, names []string, options *Rem
|
||||
IsExternalContainerFunc: options.IsExternalContainerFunc,
|
||||
Filters: options.Filters,
|
||||
}
|
||||
filteredImages, err := r.ListImages(ctx, nil, options)
|
||||
filteredImages, err := r.ListImages(ctx, options)
|
||||
if err != nil {
|
||||
appendError(err)
|
||||
return nil, rmErrors
|
||||
|
||||
Reference in New Issue
Block a user