Skip to content

Commit

Permalink
Review: use set instead of map
Browse files Browse the repository at this point in the history
  • Loading branch information
Pvlerick committed Jun 29, 2023
1 parent 23ba5b1 commit d3e5d57
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions oci/layout/oci_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/containers/image/v5/directory/explicitfilepath"
"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/internal/image"
"github.com/containers/image/v5/internal/set"
"github.com/containers/image/v5/oci/internal"
"github.com/containers/image/v5/transports"
"github.com/containers/image/v5/types"
Expand Down Expand Up @@ -264,23 +265,23 @@ func (ref ociReference) DeleteImage(ctx context.Context, sys *types.SystemContex
if err != nil {
return err
}
layersUsedByOtherImages := make(map[digest.Digest]bool, len(index.Manifests))
layersUsedByOtherImages := set.New[digest.Digest]()
for _, v := range index.Manifests {
if v.Digest != manifestDescriptor.Digest {
otherImageManifest, err := ref.getManifest(v)
if err != nil {
return err
}
for _, layer := range otherImageManifest.Layers {
layersUsedByOtherImages[layer.Digest] = true
layersUsedByOtherImages.Add(layer.Digest)
}
}
}

// Delete all blobs
blobsToDelete := make([]digest.Digest, 0, len(manifest.Layers))
for _, layer := range manifest.Layers {
if !layersUsedByOtherImages[layer.Digest] {
if !layersUsedByOtherImages.Contains(layer.Digest) {
blobsToDelete = append(blobsToDelete, layer.Digest)
}
}
Expand Down

0 comments on commit d3e5d57

Please sign in to comment.