Skip to content

Commit

Permalink
Fix OCIStore inconsistent state after AddReference (#215)
Browse files Browse the repository at this point in the history
Update descriptor in the nameMap as well as in index.Manifests.

nameMap used in the ListReferences operation and should return actual descriptor.

Co-authored-by: Josh Dolitsky <393494+jdolitsky@users.noreply.github.com>
  • Loading branch information
distorhead and jdolitsky authored Feb 4, 2021
1 parent b4a877c commit b95c322
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/content/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func (s *OCIStore) AddReference(name string, desc ocispec.Descriptor) {
}

if _, ok := s.nameMap[name]; ok {
s.nameMap[name] = desc

for i, ref := range s.index.Manifests {
if name == ref.Annotations[ocispec.AnnotationRefName] {
s.index.Manifests[i] = desc
Expand All @@ -107,11 +109,12 @@ func (s *OCIStore) AddReference(name string, desc ocispec.Descriptor) {

// Process should not reach here.
// Fallthrough to `Add` scenario and recover.
s.index.Manifests = append(s.index.Manifests, desc)
return
}

s.index.Manifests = append(s.index.Manifests, desc)
s.nameMap[name] = desc
return
}

// DeleteReference deletes an reference from index.
Expand Down

0 comments on commit b95c322

Please sign in to comment.