MCPcopy
hub / github.com/containerd/containerd / Update

Method Update

core/metadata/images.go:180–280  ·  view source on GitHub ↗
(ctx context.Context, image images.Image, fieldpaths ...string)

Source from the content-addressed store, hash-verified

178}
179
180func (s *imageStore) Update(ctx context.Context, image images.Image, fieldpaths ...string) (images.Image, error) {
181 namespace, err := namespaces.NamespaceRequired(ctx)
182 if err != nil {
183 return images.Image{}, err
184 }
185
186 if image.Name == "" {
187 return images.Image{}, fmt.Errorf("image name is required for update: %w", errdefs.ErrInvalidArgument)
188 }
189
190 var updated images.Image
191
192 if err := update(ctx, s.db, func(tx *bolt.Tx) error {
193 bkt, err := createImagesBucket(tx, namespace)
194 if err != nil {
195 return err
196 }
197
198 ibkt := bkt.Bucket([]byte(image.Name))
199 if ibkt == nil {
200 return fmt.Errorf("image %q: %w", image.Name, errdefs.ErrNotFound)
201 }
202
203 if err := readImage(&updated, ibkt); err != nil {
204 return fmt.Errorf("image %q: %w", image.Name, err)
205 }
206 createdat := updated.CreatedAt
207 updated.Name = image.Name
208
209 if len(fieldpaths) > 0 {
210 for _, path := range fieldpaths {
211 if strings.HasPrefix(path, "labels.") {
212 if updated.Labels == nil {
213 updated.Labels = map[string]string{}
214 }
215
216 key := strings.TrimPrefix(path, "labels.")
217 updated.Labels[key] = image.Labels[key]
218 continue
219 } else if strings.HasPrefix(path, "annotations.") {
220 if updated.Target.Annotations == nil {
221 updated.Target.Annotations = map[string]string{}
222 }
223
224 key := strings.TrimPrefix(path, "annotations.")
225 updated.Target.Annotations[key] = image.Target.Annotations[key]
226 continue
227 }
228
229 switch path {
230 case "labels":
231 updated.Labels = image.Labels
232 case "target":
233 // NOTE(stevvooe): While we allow setting individual labels, we
234 // only support replacing the target as a unit, since that is
235 // commonly pulled as a unit from other sources. It often doesn't
236 // make sense to modify the size or digest without touching the
237 // mediatype, as well, for example.

Callers

nothing calls this directly

Calls 10

NamespaceRequiredFunction · 0.92
FromContextFunction · 0.92
updateFunction · 0.85
createImagesBucketFunction · 0.85
readImageFunction · 0.85
validateImageFunction · 0.85
addImageLeaseFunction · 0.85
writeImageFunction · 0.85
PublisherMethod · 0.80
PublishMethod · 0.65

Tested by

no test coverage detected