From d608e3d9dc3d96316504a08e402795feb5c26ff9 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 27 Mar 2018 17:55:35 -0700 Subject: [PATCH] Fix label being put on snapshot instead of content The uncompressed label should be placed on content instead of snapshots. Currently the uncompressed label is getting passed into as a label option for apply, which is used to commit snapshots. The content is already committed, but after apply the uncompressed diff digest is verified and can be reliably used to update the content with the label. Signed-off-by: Derek McGowan --- image.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/image.go b/image.go index 1af706c7f..e2f10a903 100644 --- a/image.go +++ b/image.go @@ -25,7 +25,6 @@ import ( "github.com/containerd/containerd/images" "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/rootfs" - "github.com/containerd/containerd/snapshots" digest "github.com/opencontainers/go-digest" "github.com/opencontainers/image-spec/identity" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -124,15 +123,25 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error { unpacked bool ) for _, layer := range layers { - labels := map[string]string{ - "containerd.io/uncompressed": layer.Diff.Digest.String(), - } - - unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a, snapshots.WithLabels(labels)) + unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a) if err != nil { return err } + if unpacked { + // Set the uncompressed label after the uncompressed + // digest has been verified through apply. + cinfo := content.Info{ + Digest: layer.Blob.Digest, + Labels: map[string]string{ + "containerd.io/uncompressed": layer.Diff.Digest.String(), + }, + } + if _, err := cs.Update(ctx, cinfo, "labels.containerd.io/uncompressed"); err != nil { + return err + } + } + chain = append(chain, layer.Diff.Digest) }