Skip to content

Commit

Permalink
Add Untag() to oci.Store.
Browse files Browse the repository at this point in the history
Signed-off-by: Francis Laniel <[email protected]>
  • Loading branch information
eiffel-fl committed Dec 14, 2023
1 parent 15ee0be commit a763b1c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
27 changes: 27 additions & 0 deletions content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,33 @@ func (s *Store) Resolve(ctx context.Context, reference string) (ocispec.Descript
return desc, nil
}

func (s *Store) Untag(ctx context.Context, reference string) error {
s.sync.RLock()
defer s.sync.RUnlock()

if reference == "" {
return errdef.ErrMissingReference
}

desc, err := s.tagResolver.Resolve(ctx, reference)
if err != nil {
return fmt.Errorf("reference %q does not point to a descriptor: %w", reference, err)
}
if reference == desc.Digest.String() {
return fmt.Errorf("reference %q is a digest and not a tag", reference)
}

return s.untag(reference)
}

func (s *Store) untag(reference string) error {
s.tagResolver.Untag(reference)
if s.AutoSaveIndex {
return s.saveIndex()
}
return nil
}

// Predecessors returns the nodes directly pointing to the current node.
// Predecessors returns nil without error if the node does not exists in the
// store.
Expand Down
27 changes: 27 additions & 0 deletions content/oci/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ func TestStore_Success(t *testing.T) {
if !bytes.Equal(got, manifest) {
t.Errorf("Store.Fetch() = %v, want %v", got, manifest)
}

// test untag
err = s.Untag(ctx, ref)
if err != nil {
t.Fatal("Store.Untag() error =", err)
}
if got, want := len(internalResolver.Map()), 1; got != want {
t.Errorf("resolver.Map() = %v, want %v", got, want)
}
}

func TestStore_RelativeRoot_Success(t *testing.T) {
Expand Down Expand Up @@ -333,6 +342,15 @@ func TestStore_RelativeRoot_Success(t *testing.T) {
if !bytes.Equal(got, manifest) {
t.Errorf("Store.Fetch() = %v, want %v", got, manifest)
}

// test untag
err = s.Untag(ctx, ref)
if err != nil {
t.Fatal("Store.Untag() error =", err)
}
if got, want := len(internalResolver.Map()), 1; got != want {
t.Errorf("resolver.Map() = %v, want %v", got, want)
}
}

func TestStore_NotExistingRoot(t *testing.T) {
Expand Down Expand Up @@ -654,6 +672,15 @@ func TestStore_DisableAutoSaveIndex(t *testing.T) {
if _, err := os.Stat(s.indexPath); err != nil {
t.Errorf("error: %s does not exist", s.indexPath)
}

// test untag
err = s.Untag(ctx, ref)
if err != nil {
t.Fatal("Store.Untag() error =", err)
}
if got, want := len(internalResolver.Map()), 1; got != want {
t.Errorf("resolver.Map() = %v, want %v", got, want)
}
}

func TestStore_RepeatTag(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions content/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ type TagResolver interface {
Tagger
Resolver
}

// Untagger untags reference tags.
type Untagger interface {
// Untag untags the given reference string.
Untag(ctx context.Context, reference string) error
}

Check failure on line 47 in content/resolver.go

View workflow job for this annotation

GitHub Actions / build (1.20)

syntax error: unexpected var after top level declaration

Check failure on line 47 in content/resolver.go

View workflow job for this annotation

GitHub Actions / Analyze (1.20)

syntax error: unexpected var after top level declaration

0 comments on commit a763b1c

Please sign in to comment.