From 6f7761eb16e925d1652f0267ab451f299e7d6bee Mon Sep 17 00:00:00 2001 From: Francis Laniel Date: Tue, 21 Nov 2023 19:03:09 +0100 Subject: [PATCH] Add Untag() to oci.Store. Signed-off-by: Francis Laniel --- content/oci/oci.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/content/oci/oci.go b/content/oci/oci.go index 5d4699a1f..5d8379880 100644 --- a/content/oci/oci.go +++ b/content/oci/oci.go @@ -238,6 +238,38 @@ 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 + } + + // attempt resolving manifest + _, err := s.tagResolver.Resolve(ctx, reference) + if err != nil { + if errors.Is(err, errdef.ErrNotFound) { + // attempt resolving blob + _, err := resolveBlob(os.DirFS(s.root), reference) + if err != nil { + return err + } + } + return err + } + + 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.