exporter: avoid modifying exporter inputs

Co-authored-by: fahed dorgaa <fahed.dorgaa@gmail.com>
Co-authored-by: a-palchikov <deemok@gmail.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
Justin Chadwell
2023-08-09 12:14:38 +01:00
parent 578e8105c3
commit da231fb56e
3 changed files with 12 additions and 0 deletions

View File

@@ -188,6 +188,7 @@ func (e *imageExporterInstance) Config() *exporter.Config {
}
func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source, sessionID string) (_ map[string]string, descref exporter.DescriptorReference, err error) {
src = src.Clone()
if src.Metadata == nil {
src.Metadata = make(map[string][]byte)
}

View File

@@ -117,6 +117,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source
return nil, nil, errors.Errorf("docker exporter does not currently support exporting manifest lists")
}
src = src.Clone()
if src.Metadata == nil {
src.Metadata = make(map[string][]byte)
}

View File

@@ -1,6 +1,7 @@
package result
import (
"maps"
"sync"
"github.com/pkg/errors"
@@ -14,6 +15,15 @@ type Result[T comparable] struct {
Attestations map[string][]Attestation[T]
}
func (r *Result[T]) Clone() *Result[T] {
return &Result[T]{
Ref: r.Ref,
Refs: maps.Clone(r.Refs),
Metadata: maps.Clone(r.Metadata),
Attestations: maps.Clone(r.Attestations),
}
}
func (r *Result[T]) AddMeta(k string, v []byte) {
r.mu.Lock()
if r.Metadata == nil {