From 54658a1152edd99828f30ea2a1f4fcb25bb8f6d1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 30 May 2023 12:44:54 +0200 Subject: [PATCH 1/2] Image: rename variable that shadowed import Signed-off-by: Sebastiaan van Stijn --- image.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/image.go b/image.go index d3cfdba6f..a6d3ce58d 100644 --- a/image.go +++ b/image.go @@ -423,12 +423,12 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string, opts ...Unpa return err } - rootfs := identity.ChainID(chain).String() + rootFS := identity.ChainID(chain).String() cinfo := content.Info{ Digest: desc.Digest, Labels: map[string]string{ - fmt.Sprintf("containerd.io/gc.ref.snapshot.%s", snapshotterName): rootfs, + fmt.Sprintf("containerd.io/gc.ref.snapshot.%s", snapshotterName): rootFS, }, } From 94f0af3ece002c2c49b02b868844b0f6fec74d7d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 30 May 2023 12:46:14 +0200 Subject: [PATCH 2/2] Image.IsUnpacked(): make error-handling more iodiomatic Check for "err != nil" instead of "err == nil". Signed-off-by: Sebastiaan van Stijn --- image.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/image.go b/image.go index a6d3ce58d..82a00a6f0 100644 --- a/image.go +++ b/image.go @@ -58,7 +58,7 @@ type Image interface { Usage(context.Context, ...UsageOpt) (int64, error) // Config descriptor for the image. Config(ctx context.Context) (ocispec.Descriptor, error) - // IsUnpacked returns whether or not an image is unpacked. + // IsUnpacked returns whether an image is unpacked. IsUnpacked(context.Context, string) (bool, error) // ContentStore provides a content store which contains image blob data ContentStore() content.Store @@ -285,15 +285,14 @@ func (i *image) IsUnpacked(ctx context.Context, snapshotterName string) (bool, e return false, err } - chainID := identity.ChainID(diffs) - _, err = sn.Stat(ctx, chainID.String()) - if err == nil { - return true, nil - } else if !errdefs.IsNotFound(err) { + if _, err := sn.Stat(ctx, identity.ChainID(diffs).String()); err != nil { + if errdefs.IsNotFound(err) { + return false, nil + } return false, err } - return false, nil + return true, nil } func (i *image) Spec(ctx context.Context) (ocispec.Image, error) {