diff --git a/core/images/archive/exporter.go b/core/images/archive/exporter.go index 58a17daecd..d736949fbe 100644 --- a/core/images/archive/exporter.go +++ b/core/images/archive/exporter.go @@ -22,6 +22,7 @@ import ( "encoding/json" "fmt" "io" + "maps" "path" "slices" "sort" @@ -195,9 +196,7 @@ func WithSkipMissing(store content.InfoReaderProvider) ExportOpt { func addNameAnnotation(name string, base map[string]string) map[string]string { annotations := map[string]string{} - for k, v := range base { - annotations[k] = v - } + maps.Copy(annotations, base) annotations[images.AnnotationImageName] = name annotations[ocispec.AnnotationRefName] = ociReferenceName(name) diff --git a/core/leases/lease.go b/core/leases/lease.go index d842c4081a..478e7fd47d 100644 --- a/core/leases/lease.go +++ b/core/leases/lease.go @@ -18,6 +18,7 @@ package leases import ( "context" + "maps" "time" ) @@ -84,9 +85,7 @@ func WithLabels(labels map[string]string) Opt { if l.Labels == nil { l.Labels = map[string]string{} } - for k, v := range labels { - l.Labels[k] = v - } + maps.Copy(l.Labels, labels) return nil } } diff --git a/core/leases/lease_test.go b/core/leases/lease_test.go index c1f547f1b5..b6e1f0a6f0 100644 --- a/core/leases/lease_test.go +++ b/core/leases/lease_test.go @@ -17,6 +17,7 @@ package leases import ( + "maps" "testing" "github.com/stretchr/testify/assert" @@ -80,9 +81,7 @@ func newLease(labels map[string]string) *Lease { lease := &Lease{} if labels != nil { lease.Labels = map[string]string{} - for k, v := range labels { - lease.Labels[k] = v - } + maps.Copy(lease.Labels, labels) } return lease } diff --git a/core/metadata/snapshot.go b/core/metadata/snapshot.go index 6fd4615a04..5880df57ec 100644 --- a/core/metadata/snapshot.go +++ b/core/metadata/snapshot.go @@ -19,6 +19,7 @@ package metadata import ( "context" "fmt" + "maps" "strings" "sync" "time" @@ -250,9 +251,7 @@ func overlayInfo(info, overlay snapshots.Info) snapshots.Info { if info.Labels == nil { info.Labels = overlay.Labels } else { - for k, v := range overlay.Labels { - info.Labels[k] = v - } + maps.Copy(info.Labels, overlay.Labels) } return info } diff --git a/core/metadata/snapshot_test.go b/core/metadata/snapshot_test.go index 83874ee5b4..e005cb898d 100644 --- a/core/metadata/snapshot_test.go +++ b/core/metadata/snapshot_test.go @@ -19,6 +19,7 @@ package metadata import ( "context" "fmt" + "maps" "reflect" "sync" "testing" @@ -291,9 +292,7 @@ func (s *tmpSnapshotter) Update(ctx context.Context, info snapshots.Info, fieldp return snapshots.Info{}, errdefs.ErrNotFound } - for k, v := range info.Labels { - i.Labels[k] = v - } + maps.Copy(i.Labels, info.Labels) s.snapshots[i.Name] = i diff --git a/core/snapshots/snapshotter.go b/core/snapshots/snapshotter.go index 8bd4618841..a369baf379 100644 --- a/core/snapshots/snapshotter.go +++ b/core/snapshots/snapshotter.go @@ -19,6 +19,7 @@ package snapshots import ( "context" "encoding/json" + "maps" "strings" "time" @@ -371,9 +372,7 @@ func WithLabels(labels map[string]string) Opt { info.Labels = make(map[string]string) } - for k, v := range labels { - info.Labels[k] = v - } + maps.Copy(info.Labels, labels) return nil } diff --git a/core/transfer/local/import.go b/core/transfer/local/import.go index 9f8a177094..232981b764 100644 --- a/core/transfer/local/import.go +++ b/core/transfer/local/import.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "maps" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -159,11 +160,7 @@ func (ts *localTransferService) importStream(ctx context.Context, i transfer.Ima func mergeMap(m1, m2 map[string]string) map[string]string { merged := make(map[string]string, len(m1)+len(m2)) - for k, v := range m1 { - merged[k] = v - } - for k, v := range m2 { - merged[k] = v - } + maps.Copy(merged, m1) + maps.Copy(merged, m2) return merged }