Skip to content

Commit

Permalink
feat: implement referrers deletion (#54)
Browse files Browse the repository at this point in the history
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 authored Jan 6, 2023
1 parent 474bc48 commit f27b092
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
37 changes: 36 additions & 1 deletion registry/storage/manifeststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,42 @@ func (ms *manifestStore) Put(ctx context.Context, manifest distribution.Manifest
// Delete removes the revision of the specified manifest.
func (ms *manifestStore) Delete(ctx context.Context, dgst digest.Digest) error {
dcontext.GetLogger(ms.ctx).Debug("(*manifestStore).Delete")
return ms.blobStore.Delete(ctx, dgst)

if !ms.blobStore.deleteEnabled {
return distribution.ErrUnsupported
}

// Ensure the blob is available for deletion
_, err := ms.blobStore.Stat(ctx, dgst)
if err != nil {
return err
}

// Remove the manifest from its subject's indexed referrers, if applicable
man, err := ms.Get(ctx, dgst)
if err != nil {
return fmt.Errorf("unable to retrieve manifest: %w", err)
}

var subject *distribution.Descriptor
switch m := man.(type) {
case *ociartifact.DeserializedManifest:
subject = m.Subject
case *ocischema.DeserializedManifest:
subject = m.Subject
}

if subject != nil {
referrersLinkPath, err := pathFor(referrersLinkPathSpec{name: ms.repository.Named().Name(), revision: dgst, subjectRevision: subject.Digest})
if err != nil {
return fmt.Errorf("failed to generate referrers link path for %v", dgst)
}
if err = ms.repository.driver.Delete(ctx, referrersLinkPath); err != nil {
return err
}
}

return ms.blobStore.blobAccessController.Clear(ctx, dgst)
}

func (ms *manifestStore) Enumerate(ctx context.Context, ingester func(digest.Digest) error) error {
Expand Down
6 changes: 3 additions & 3 deletions registry/storage/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const (
// startedat
// hashstates/<algorithm>/<offset>
// -> _referrers/subjects
// -> <revision digest path>
// -> <subject digest path>/link
// -> <subject digest path>
// -> <revision digest path>/link
//
// -> blob/<algorithm>
// <split directory content addressable storage>
Expand Down Expand Up @@ -101,7 +101,7 @@ const (
//
// Referrers:
//
// referrersLinkPathSpec: <root>/v2/repositories/<name>/_referrers/subjects/<algorithm>/<hex digest>/<subject algorithm>/<subject hex digest>/link
// referrersLinkPathSpec: <root>/v2/repositories/<name>/_referrers/subjects/<subject algorithm>/<subject hex digest>/<algorithm>/<hex digest>/link
//
// Blob Store:
//
Expand Down

0 comments on commit f27b092

Please sign in to comment.