From f7a33920206b7271fa41ec0c53ae95857b658d56 Mon Sep 17 00:00:00 2001 From: MinerYang Date: Wed, 13 Mar 2024 14:46:11 +0800 Subject: [PATCH] Update deletion for index type of accessory (#20073) update delete for index accessory Signed-off-by: yminer revert error code update lint and comments --- src/controller/artifact/controller.go | 18 ++++++++++++++++-- src/server/registry/manifest.go | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/controller/artifact/controller.go b/src/controller/artifact/controller.go index 0e710c064..cc100211f 100644 --- a/src/controller/artifact/controller.go +++ b/src/controller/artifact/controller.go @@ -356,7 +356,16 @@ 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 + } + if err = c.deleteDeeply(ctx, acc.GetData().ArtifactID, len(parents) == 0, true); err != nil { return err } } @@ -369,7 +378,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 } } diff --git a/src/server/registry/manifest.go b/src/server/registry/manifest.go index 4693c3a7e..6cf02486a 100644 --- a/src/server/registry/manifest.go +++ b/src/server/registry/manifest.go @@ -145,6 +145,8 @@ 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. + // According to https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#deleting-tags + // 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)) return