vendor: update c/common + libhvee to latest main

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-02-05 17:10:24 +01:00
parent f439f4e9da
commit 5de4bd5d13
10 changed files with 731 additions and 69 deletions

View File

@@ -6,10 +6,12 @@ import (
"fmt"
"os"
"github.com/containers/common/internal"
"github.com/containers/image/v5/manifest"
digest "github.com/opencontainers/go-digest"
imgspec "github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"golang.org/x/exp/slices"
)
// List is a generic interface for manipulating a manifest list or an image
@@ -36,8 +38,10 @@ type List interface {
OSFeatures(instanceDigest digest.Digest) ([]string, error)
SetMediaType(instanceDigest digest.Digest, mediaType string) error
MediaType(instanceDigest digest.Digest) (string, error)
SetArtifactType(instanceDigest digest.Digest, artifactType string) error
ArtifactType(instanceDigest digest.Digest) (string, error)
SetArtifactType(instanceDigest *digest.Digest, artifactType string) error
ArtifactType(instanceDigest *digest.Digest) (string, error)
SetSubject(subject *v1.Descriptor) error
Subject() (*v1.Descriptor, error)
Serialize(mimeType string) ([]byte, error)
Instances() []digest.Digest
OCIv1() *v1.Index
@@ -469,22 +473,50 @@ func (l *list) MediaType(instanceDigest digest.Digest) (string, error) {
}
// SetArtifactType sets the ArtifactType field in the instance with the specified digest.
func (l *list) SetArtifactType(instanceDigest digest.Digest, artifactType string) error {
oci, err := l.findOCIv1(instanceDigest)
if err != nil {
return err
func (l *list) SetArtifactType(instanceDigest *digest.Digest, artifactType string) error {
artifactTypePtr := &l.oci.ArtifactType
if instanceDigest != nil {
oci, err := l.findOCIv1(*instanceDigest)
if err != nil {
return err
}
artifactTypePtr = &oci.ArtifactType
}
oci.ArtifactType = artifactType
*artifactTypePtr = artifactType
return nil
}
// ArtifactType retrieves the ArtifactType field in the instance with the specified digest.
func (l *list) ArtifactType(instanceDigest digest.Digest) (string, error) {
oci, err := l.findOCIv1(instanceDigest)
if err != nil {
return "", err
func (l *list) ArtifactType(instanceDigest *digest.Digest) (string, error) {
artifactTypePtr := &l.oci.ArtifactType
if instanceDigest != nil {
oci, err := l.findOCIv1(*instanceDigest)
if err != nil {
return "", err
}
artifactTypePtr = &oci.ArtifactType
}
return oci.ArtifactType, nil
return *artifactTypePtr, nil
}
// SetSubject sets the image index's subject.
// The field is specific to the OCI image index format, and is not present in Docker manifest lists.
func (l *list) SetSubject(subject *v1.Descriptor) error {
if subject != nil {
subject = internal.DeepCopyDescriptor(subject)
}
l.oci.Subject = subject
return nil
}
// Subject retrieves the subject which might have been set on the image index.
// The field is specific to the OCI image index format, and is not present in Docker manifest lists.
func (l *list) Subject() (*v1.Descriptor, error) {
s := l.oci.Subject
if s != nil {
s = internal.DeepCopyDescriptor(s)
}
return s, nil
}
// FromBlob builds a list from an encoded manifest list or image index.
@@ -530,11 +562,19 @@ func FromBlob(manifestBytes []byte) (List, error) {
if platform == nil {
platform = &v1.Platform{}
}
if m.Platform != nil && m.Platform.OSFeatures != nil {
platform.OSFeatures = slices.Clone(m.Platform.OSFeatures)
}
var urls []string
if m.URLs != nil {
urls = slices.Clone(m.URLs)
}
list.docker.Manifests = append(list.docker.Manifests, manifest.Schema2ManifestDescriptor{
Schema2Descriptor: manifest.Schema2Descriptor{
MediaType: m.MediaType,
Size: m.Size,
Digest: m.Digest,
URLs: urls,
},
Platform: manifest.Schema2PlatformSpec{
Architecture: platform.Architecture,
@@ -557,6 +597,9 @@ func (l *list) preferOCI() bool {
if l.oci.Subject != nil {
return true
}
if len(l.oci.Annotations) > 0 {
return true
}
for _, m := range l.oci.Manifests {
if m.ArtifactType != "" {
return true

View File

@@ -0,0 +1,65 @@
package strongunits
// supported units
// B represents bytes
type B uint64
// KiB represents KiB
type KiB uint64
// MiB represents MiB
type MiB uint64
// GiB represents GiB
type GiB uint64
const (
// kibToB is the math convert from bytes to KiB
kibToB = 1 << 10
// mibToB is the math to convert from bytes to MiB
mibToB = 1 << 20
// gibToB s the math to convert from bytes to GiB
gibToB = 1 << 30
)
// StorageUnits is an interface for converting disk/memory storage
// units amongst each other.
type StorageUnits interface {
ToBytes() B
}
// ToBytes is a pass-through function for bytes
func (b B) ToBytes() B {
return b
}
// ToBytes converts KiB to bytes
func (k KiB) ToBytes() B {
return B(k * kibToB)
}
// ToBytes converts MiB to bytes
func (m MiB) ToBytes() B {
return B(m * mibToB)
}
// ToBytes converts GiB to bytes
func (g GiB) ToBytes() B {
return B(g * gibToB)
}
// ToKiB converts any StorageUnit type to KiB
func ToKiB(b StorageUnits) KiB {
return KiB(b.ToBytes() >> 10)
}
// ToMib converts any StorageUnit type to MiB
func ToMib(b StorageUnits) MiB {
return MiB(b.ToBytes() >> 20)
}
// ToGiB converts any StorageUnit type to GiB
func ToGiB(b StorageUnits) GiB {
return GiB(b.ToBytes() >> 30)
}