File: deepcopy.go

package info (click to toggle)
golang-github-containers-common 0.64.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 5,932 kB
  • sloc: makefile: 132; sh: 111
file content (30 lines) | stat: -rw-r--r-- 724 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package internal

import (
	"maps"
	"slices"

	v1 "github.com/opencontainers/image-spec/specs-go/v1"
)

// DeepCopyDescriptor copies a Descriptor, deeply copying its contents
func DeepCopyDescriptor(original *v1.Descriptor) *v1.Descriptor {
	tmp := *original
	if original.URLs != nil {
		tmp.URLs = slices.Clone(original.URLs)
	}
	if original.Annotations != nil {
		tmp.Annotations = maps.Clone(original.Annotations)
	}
	if original.Data != nil {
		tmp.Data = slices.Clone(original.Data)
	}
	if original.Platform != nil {
		tmpPlatform := *original.Platform
		if original.Platform.OSFeatures != nil {
			tmpPlatform.OSFeatures = slices.Clone(original.Platform.OSFeatures)
		}
		tmp.Platform = &tmpPlatform
	}
	return &tmp
}