Skip to content

Commit

Permalink
update calculation for the expected bytes during image layer pulls (#…
Browse files Browse the repository at this point in the history
…1489)

## Description

The progress bar 'expected bytes' now takes duplicate layers into
account

Fixes #1488

Signed-off-by: Jon Perry <[email protected]>
Co-authored-by: Wayne Starr <[email protected]>
  • Loading branch information
YrrepNoj and Racer159 authored Mar 27, 2023
1 parent ff8b5d6 commit d9d0dc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
7 changes: 6 additions & 1 deletion src/pkg/packager/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d9d0dc6

Please sign in to comment.