Skip to content

Commit

Permalink
history: set Tags
Browse files Browse the repository at this point in the history
Correctly set the tags of history layers.  Also make sure to nil the
loop `layer` variable when it has no parent.

Fixes: containers/podman/issues/17763
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
  • Loading branch information
vrothberg committed May 2, 2023
1 parent 0f2dc33 commit dbba228
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libimage/history.go
Expand Up @@ -51,7 +51,6 @@ func (i *Image) History(ctx context.Context) ([]ImageHistory, error) {
}

if layer != nil {
history.Tags = layer.Names
if !ociImage.History[x].EmptyLayer {
history.Size = layer.UncompressedSize
}
Expand All @@ -64,8 +63,13 @@ func (i *Image) History(ctx context.Context) ([]ImageHistory, error) {
history.ID = id
usedIDs[id] = true
}
for i := range node.images {
history.Tags = append(history.Tags, node.images[i].Names()...)
}
}
if layer.Parent != "" && !ociImage.History[x].EmptyLayer {
if layer.Parent == "" {
layer = nil
} else if !ociImage.History[x].EmptyLayer {
layer, err = i.runtime.store.Layer(layer.Parent)
if err != nil {
return nil, err
Expand Down
28 changes: 28 additions & 0 deletions libimage/history_test.go
@@ -0,0 +1,28 @@
package libimage

import (
"context"
"testing"

"github.com/containers/common/pkg/config"
"github.com/stretchr/testify/require"
)

func TestHistory(t *testing.T) {
runtime, cleanup := testNewRuntime(t)
defer cleanup()
ctx := context.Background()

name := "quay.io/libpod/alpine:3.10.2"
pullOptions := &PullOptions{}
pulledImages, err := runtime.Pull(ctx, name, config.PullPolicyAlways, pullOptions)
require.NoError(t, err)
require.Len(t, pulledImages, 1)

history, err := pulledImages[0].History(ctx)
require.NoError(t, err)
require.Len(t, history, 2)

require.Equal(t, []string{name}, history[0].Tags)
require.Len(t, history[1].Tags, 0)
}

0 comments on commit dbba228

Please sign in to comment.