From d9d0dc6a4e054f3859ab734bf6fd02938353129d Mon Sep 17 00:00:00 2001 From: Jonathan Perry Date: Mon, 27 Mar 2023 14:58:24 -0400 Subject: [PATCH] update calculation for the expected bytes during image layer pulls (#1489) ## Description The progress bar 'expected bytes' now takes duplicate layers into account Fixes #1488 Signed-off-by: Jon Perry Co-authored-by: Wayne Starr --- src/internal/packager/images/pull.go | 17 ++++++++++++++--- src/pkg/packager/network.go | 7 ++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/internal/packager/images/pull.go b/src/internal/packager/images/pull.go index 28ee34b61f..0e697a5826 100644 --- a/src/internal/packager/images/pull.go +++ b/src/internal/packager/images/pull.go @@ -70,6 +70,7 @@ func (i *ImgConfig) PullAll() error { } totalBytes := int64(0) + processedLayers := make(map[string]bool) for src, img := range imageMap { tag, err := name.NewTag(src, name.WeakValidation) if err != nil { @@ -82,11 +83,21 @@ func (i *ImgConfig) PullAll() error { return fmt.Errorf("unable to get layers for image %s: %w", src, err) } for _, layer := range layers { - size, err := layer.Size() + layerDigest, err := layer.Digest() if err != nil { - return fmt.Errorf("unable to get size of layer: %w", err) + return fmt.Errorf("unable to get digest for image layer: %w", err) } - totalBytes += size + + // Only calculate this layer size if we haven't already looked at it + if !processedLayers[layerDigest.Hex] { + size, err := layer.Size() + if err != nil { + return fmt.Errorf("unable to get size of layer: %w", err) + } + totalBytes += size + processedLayers[layerDigest.Hex] = true + } + } } spinner.Updatef("Preparing image sources and cache for image pulling") diff --git a/src/pkg/packager/network.go b/src/pkg/packager/network.go index 4ddb688a75..b9eb25dca2 100644 --- a/src/pkg/packager/network.go +++ b/src/pkg/packager/network.go @@ -252,8 +252,13 @@ func getOCIPackageSize(src *utils.OrasRemote, ref registry.Reference) (int64, er layers = manifest.Layers } + processedLayers := make(map[string]bool) for _, layer := range layers { - total += layer.Size + // Only include this layer's size if we haven't already processed it + if !processedLayers[layer.Digest.String()] { + total += layer.Size + processedLayers[layer.Digest.String()] = true + } } return total, nil