fix the copy artifact issue (#18441)

support copy artifact with multipe levels of accessories.

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2023-03-30 02:04:22 +08:00 committed by GitHub
parent d22c94b4fa
commit f63865d207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,