DescriptorWrite writes a descriptor to the cache index; it validates that it has a name and replaces any existing one
(image string, desc v1.Descriptor)
| 473 | // DescriptorWrite writes a descriptor to the cache index; it validates that it has a name |
| 474 | // and replaces any existing one |
| 475 | func (p *Provider) DescriptorWrite(image string, desc v1.Descriptor) error { |
| 476 | if image == "" { |
| 477 | return errors.New("cannot write descriptor without reference name") |
| 478 | } |
| 479 | if desc.Annotations == nil { |
| 480 | desc.Annotations = map[string]string{} |
| 481 | } |
| 482 | desc.Annotations[imagespec.AnnotationRefName] = image |
| 483 | log.Debugf("writing descriptor for image %s", image) |
| 484 | |
| 485 | // get our lock |
| 486 | if err := p.Lock(); err != nil { |
| 487 | return fmt.Errorf("unable to lock cache for writing descriptors: %v", err) |
| 488 | } |
| 489 | defer p.Unlock() |
| 490 | |
| 491 | // get our lock |
| 492 | // do we update an existing one? Or create a new one? |
| 493 | if err := p.cache.RemoveDescriptors(match.Name(image)); err != nil { |
| 494 | return fmt.Errorf("unable to remove old descriptors for %s: %v", image, err) |
| 495 | } |
| 496 | |
| 497 | if err := p.cache.AppendDescriptor(desc); err != nil { |
| 498 | return fmt.Errorf("unable to append new descriptor for %s: %v", image, err) |
| 499 | } |
| 500 | |
| 501 | return nil |
| 502 | } |
| 503 | |
| 504 | // RemoveDescriptors removes all descriptors that match the provided matcher. |
| 505 | // It does so in a parallel-access-safe way |
no test coverage detected