@ -17,46 +17,46 @@ import (
"golang.org/x/sync/errgroup"
)
func ( r * Resolver ) Combine ( ctx context . Context , in string , descs [ ] ocispec . Descriptor ) ( [ ] byte , ocispec . Descriptor , error ) {
ref , err := parseRef ( in )
if err != nil {
return nil , ocispec . Descriptor { } , err
}
type Source struct {
Desc ocispec . Descriptor
Ref reference . Named
}
func ( r * Resolver ) Combine ( ctx context . Context , srcs [ ] * Source ) ( [ ] byte , ocispec . Descriptor , error ) {
eg , ctx := errgroup . WithContext ( ctx )
dts := make ( [ ] [ ] byte , len ( de scs) )
dts := make ( [ ] [ ] byte , len ( sr cs) )
for i := range dts {
func ( i int ) {
eg . Go ( func ( ) error {
dt , err := r . GetDescriptor ( ctx , ref. String ( ) , de scs[ i ] )
dt , err := r . GetDescriptor ( ctx , s rcs[ i ] . R ef. String ( ) , sr cs[ i ] . Desc )
if err != nil {
return err
}
dts [ i ] = dt
if de scs[ i ] . MediaType == "" {
if sr cs[ i ] . Desc . MediaType == "" {
mt , err := detectMediaType ( dt )
if err != nil {
return err
}
de scs[ i ] . MediaType = mt
sr cs[ i ] . Desc . MediaType = mt
}
mt := de scs[ i ] . MediaType
mt := sr cs[ i ] . Desc . MediaType
switch mt {
case images . MediaTypeDockerSchema2Manifest , ocispec . MediaTypeImageManifest :
p := de scs[ i ] . Platform
if de scs[ i ] . Platform == nil {
p := sr cs[ i ] . Desc . Platform
if sr cs[ i ] . Desc . Platform == nil {
p = & ocispec . Platform { }
}
if p . OS == "" || p . Architecture == "" {
if err := r . loadPlatform ( ctx , p , in, dt ) ; err != nil {
if err := r . loadPlatform ( ctx , p , srcs[ i ] . Ref . Str ing( ) , dt ) ; err != nil {
return err
}
}
de scs[ i ] . Platform = p
sr cs[ i ] . Desc . Platform = p
case images . MediaTypeDockerSchema1Manifest :
return errors . Errorf ( "schema1 manifests are not allowed in manifest lists" )
}
@ -71,14 +71,14 @@ func (r *Resolver) Combine(ctx context.Context, in string, descs []ocispec.Descr
}
// on single source, return original bytes
if len ( de scs) == 1 {
if mt := de scs[ 0 ] . MediaType ; mt == images . MediaTypeDockerSchema2ManifestList || mt == ocispec . MediaTypeImageIndex {
return dts [ 0 ] , de scs[ 0 ] , nil
if len ( sr cs) == 1 {
if mt := sr cs[ 0 ] . Desc . MediaType ; mt == images . MediaTypeDockerSchema2ManifestList || mt == ocispec . MediaTypeImageIndex {
return dts [ 0 ] , sr cs[ 0 ] . Desc , nil
}
}
m := map [ digest . Digest ] int { }
newDescs := make ( [ ] ocispec . Descriptor , 0 , len ( de scs) )
newDescs := make ( [ ] ocispec . Descriptor , 0 , len ( sr cs) )
addDesc := func ( d ocispec . Descriptor ) {
idx , ok := m [ d . Digest ]
@ -103,8 +103,8 @@ func (r *Resolver) Combine(ctx context.Context, in string, descs []ocispec.Descr
}
}
for i , de sc := range de scs {
switch d esc. MediaType {
for i , sr c := range sr cs {
switch src. D esc. MediaType {
case images . MediaTypeDockerSchema2ManifestList , ocispec . MediaTypeImageIndex :
var mfst ocispec . Index
if err := json . Unmarshal ( dts [ i ] , & mfst ) ; err != nil {
@ -114,7 +114,7 @@ func (r *Resolver) Combine(ctx context.Context, in string, descs []ocispec.Descr
addDesc ( d )
}
default :
addDesc ( d esc)
addDesc ( src. D esc)
}
}