Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libimage: fix Exists
Commit 28e4555 introduced a regression to Exists() which would
return an error if the image does not exist.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
  • Loading branch information
vrothberg committed Jun 10, 2021
1 parent 231ffa0 commit 2686c15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion libimage/corrupted_test.go
Expand Up @@ -24,6 +24,10 @@ func TestCorruptedImage(t *testing.T) {

imageName := "quay.io/libpod/alpine_nginx:latest"

exists, err := runtime.Exists(imageName)
require.NoError(t, err, "image does not exist yet")
require.False(t, exists, "image does not exist yet")

pulledImages, err := runtime.Pull(ctx, imageName, config.PullPolicyAlways, pullOptions)
require.NoError(t, err)
require.Len(t, pulledImages, 1)
Expand All @@ -33,7 +37,7 @@ func TestCorruptedImage(t *testing.T) {
_, err = image.Inspect(ctx, false)
require.NoError(t, err, "inspecting healthy image should work")

exists, err := runtime.Exists(imageName)
exists, err = runtime.Exists(imageName)
require.NoError(t, err, "healthy image exists")
require.True(t, exists, "healthy image exists")

Expand Down
5 changes: 4 additions & 1 deletion libimage/runtime.go
Expand Up @@ -135,9 +135,12 @@ func (r *Runtime) storageToImage(storageImage *storage.Image, ref types.ImageRef
// storage. Note that it may return false if an image corrupted.
func (r *Runtime) Exists(name string) (bool, error) {
image, _, err := r.LookupImage(name, &LookupImageOptions{IgnorePlatform: true})
if image == nil || err != nil && errors.Cause(err) != storage.ErrImageUnknown {
if err != nil && errors.Cause(err) != storage.ErrImageUnknown {
return false, err
}
if image == nil {
return false, nil
}
// Inspect the image to make sure if it's corrupted or not.
if _, err := image.Inspect(context.Background(), false); err != nil {
logrus.Errorf("Image %s exists in local storage but may be corrupted: %v", name, err)
Expand Down

0 comments on commit 2686c15

Please sign in to comment.