Skip to content

Commit

Permalink
update delete for index accessory
Browse files Browse the repository at this point in the history
Signed-off-by: yminer <[email protected]>
  • Loading branch information
MinerYang committed Mar 1, 2024
1 parent d79e4b1 commit 9ab1321
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/controller/artifact/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,20 @@ func (c *controller) deleteDeeply(ctx context.Context, id int64, isRoot, isAcces
for _, acc := range art.Accessories {
// only hard ref accessory should be removed
if acc.IsHard() {
if err = c.deleteDeeply(ctx, acc.GetData().ArtifactID, true, true); err != nil {
//if this acc artifact has parent(is child), set isRoot to false
parents, err := c.artMgr.ListReferences(ctx, &q.Query{
Keywords: map[string]interface{}{
"ChildID": acc.GetData().ArtifactID,
},
})
if err != nil {
return err
}
// isRoot := true
// if len(parents) > 0 {
// isRoot = false
// }
if err = c.deleteDeeply(ctx, acc.GetData().ArtifactID, len(parents) == 0, true); err != nil {
return err
}
}
Expand All @@ -369,7 +382,12 @@ func (c *controller) deleteDeeply(ctx context.Context, id int64, isRoot, isAcces
!errors.IsErr(err, errors.NotFoundCode) {
return err
}
if err = c.deleteDeeply(ctx, reference.ChildID, false, false); err != nil {
// if the child artifact is an accessory, set isAccessory to true
accs, err := c.accessoryMgr.List(ctx, q.New(q.KeyWords{"ArtifactID": reference.ChildID}))
if err != nil {
return err
}
if err = c.deleteDeeply(ctx, reference.ChildID, false, len(accs) > 0); err != nil {
return err
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/server/registry/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ func deleteManifest(w http.ResponseWriter, req *http.Request) {
// add parse digest here is to return ErrDigestInvalidFormat before GetByReference throws an NOT_FOUND(404)
// Do not add the logic into GetByReference as it's a shared method for PUT/GET/DELETE/Internal call,
// and NOT_FOUND satisfy PUT/GET/Internal call.
// If tag deletion is disabled, the registry MUST respond with either a 400 Bad Request or a 405 Method Not Allowed
if _, err := digest.Parse(reference); err != nil {
lib_http.SendError(w, errors.Wrapf(err, "unsupported digest %s", reference).WithCode(errors.UNSUPPORTED))
lib_http.SendError(w, errors.Wrapf(err, "unsupported digest %s", reference).WithCode(errors.BadRequestCode))
return
}
art, err := artifact.Ctl.GetByReference(req.Context(), repository, reference, nil)
Expand Down

0 comments on commit 9ab1321

Please sign in to comment.