Skip to content

Commit

Permalink
Move shared code outside of the switch
Browse files Browse the repository at this point in the history
Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Sep 3, 2024
1 parent c82a793 commit d8c1431
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions oci/layout/oci_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ func (ref ociReference) DeleteImage(ctx context.Context, sys *types.SystemContex

// countBlobsForDescriptor updates dest with usage counts of blobs required for descriptor, INCLUDING descriptor itself.
func (ref ociReference) countBlobsForDescriptor(dest map[digest.Digest]int, descriptor *imgspecv1.Descriptor, sharedBlobsDir string) error {
blobPath, err := ref.blobPath(descriptor.Digest, sharedBlobsDir)
if err != nil {
return err
}

dest[descriptor.Digest]++
switch descriptor.MediaType {
case imgspecv1.MediaTypeImageManifest:
blobPath, err := ref.blobPath(descriptor.Digest, sharedBlobsDir)
if err != nil {
return err
}
manifest, err := parseJSON[imgspecv1.Manifest](blobPath)
if err != nil {
return err
Expand All @@ -63,10 +64,6 @@ func (ref ociReference) countBlobsForDescriptor(dest map[digest.Digest]int, desc
dest[layer.Digest]++
}
case imgspecv1.MediaTypeImageIndex:
blobPath, err := ref.blobPath(descriptor.Digest, sharedBlobsDir)
if err != nil {
return err
}
index, err := parseIndex(blobPath)
if err != nil {
return err
Expand Down

0 comments on commit d8c1431

Please sign in to comment.