MCPcopy
hub / github.com/google/go-containerregistry / replaceDescriptor

Method replaceDescriptor

pkg/v1/layout/write.go:129–162  ·  view source on GitHub ↗

replaceDescriptor adds a descriptor to the index.json of the Path, replacing any one matching matcher, if found.

(appendable mutate.Appendable, matcher match.Matcher, options ...Option)

Source from the content-addressed store, hash-verified

127// replaceDescriptor adds a descriptor to the index.json of the Path, replacing
128// any one matching matcher, if found.
129func (l Path) replaceDescriptor(appendable mutate.Appendable, matcher match.Matcher, options ...Option) error {
130 ii, err := l.ImageIndex()
131 if err != nil {
132 return err
133 }
134
135 desc, err := partial.Descriptor(appendable)
136 if err != nil {
137 return err
138 }
139
140 o := makeOptions(options...)
141 for _, opt := range o.descOpts {
142 opt(desc)
143 }
144
145 add := mutate.IndexAddendum{
146 Add: appendable,
147 Descriptor: *desc,
148 }
149 ii = mutate.AppendManifests(mutate.RemoveManifests(ii, matcher), add)
150
151 index, err := ii.IndexManifest()
152 if err != nil {
153 return err
154 }
155
156 rawIndex, err := json.MarshalIndent(index, "", " ")
157 if err != nil {
158 return err
159 }
160
161 return l.WriteFile("index.json", rawIndex, os.ModePerm)
162}
163
164// RemoveDescriptors removes any descriptors that match the match.Matcher from the index.json of the Path.
165func (l Path) RemoveDescriptors(matcher match.Matcher) error {

Callers 2

ReplaceImageMethod · 0.95
ReplaceIndexMethod · 0.95

Calls 7

ImageIndexMethod · 0.95
WriteFileMethod · 0.95
DescriptorFunction · 0.92
AppendManifestsFunction · 0.92
RemoveManifestsFunction · 0.92
makeOptionsFunction · 0.70
IndexManifestMethod · 0.65

Tested by

no test coverage detected