From f63865d2079dc86018b1bc856ba25983ae2af683 Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Thu, 30 Mar 2023 02:04:22 +0800 Subject: [PATCH] fix the copy artifact issue (#18441) support copy artifact with multipe levels of accessories. Signed-off-by: wang yan --- src/controller/artifact/controller.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/controller/artifact/controller.go b/src/controller/artifact/controller.go index 3d240d74c..3419f6b35 100644 --- a/src/controller/artifact/controller.go +++ b/src/controller/artifact/controller.go @@ -19,6 +19,7 @@ import ( "context" stderrors "errors" "fmt" + "os" "strings" "time" @@ -487,6 +488,21 @@ func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo // copy accessory if contains any for _, acc := range srcArt.Accessories { + accs, err := c.accessoryMgr.List(ctx, q.New(q.KeyWords{"SubjectArtifactRepo": srcRepo, "SubjectArtifactDigest": acc.GetData().Digest})) + if err != nil { + return 0, err + } + // copy the fork which root is the accessory self with a temp array + // to avoid infinite recursion, disable this part in UT. + if os.Getenv("UTTEST") != "true" { + if len(accs) > 0 { + tmpDstAccs := make([]*accessorymodel.AccessoryData, 0) + _, err = c.copyDeeply(ctx, srcRepo, acc.GetData().Digest, dstRepo, true, false, &tmpDstAccs) + if err != nil { + return 0, err + } + } + } dstAcc := &accessorymodel.AccessoryData{ Digest: acc.GetData().Digest, Type: acc.GetData().Type,