From 8d05007eb5671c324c69370f9a0e51a375c96414 Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Thu, 17 Feb 2022 12:43:09 +0800 Subject: [PATCH] fix accessory copy for index (#16378) When issue an copy, it has to copy the reference's accessory as well Signed-off-by: Wang Yan --- src/controller/artifact/controller.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/controller/artifact/controller.go b/src/controller/artifact/controller.go index e332f6004..cb5eddf68 100644 --- a/src/controller/artifact/controller.go +++ b/src/controller/artifact/controller.go @@ -453,10 +453,8 @@ func (c *controller) Copy(ctx context.Context, srcRepo, reference, dstRepo strin // "copyDeeply" iterates the child artifacts and copy them first func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo string, isRoot, isAcc bool, dstAccs *[]accessorymodel.AccessoryData) (int64, error) { var option *Option - // only get the tags of the root parent - if isRoot { - option = &Option{WithTag: true, WithAccessory: true} - } else if isAcc { + option = &Option{WithTag: true, WithAccessory: true} + if isAcc { option = &Option{WithTag: true} } @@ -481,6 +479,14 @@ func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo return 0, err } + // the artifact doesn't exist under the destination repository, continue to copy + // copy child artifacts if contains any + for _, reference := range srcArt.References { + if _, err = c.copyDeeply(ctx, srcRepo, reference.ChildDigest, dstRepo, false, false, dstAccs); err != nil { + return 0, err + } + } + // copy accessory if contains any for _, acc := range srcArt.Accessories { id, err := c.copyDeeply(ctx, srcRepo, acc.GetData().Digest, dstRepo, false, true, dstAccs) @@ -496,14 +502,6 @@ func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo *dstAccs = append(*dstAccs, dstAcc) } - // the artifact doesn't exist under the destination repository, continue to copy - // copy child artifacts if contains any - for _, reference := range srcArt.References { - if _, err = c.copyDeeply(ctx, srcRepo, reference.ChildDigest, dstRepo, false, false, dstAccs); err != nil { - return 0, err - } - } - // copy the parent artifact into the backend docker registry if err := c.regCli.Copy(srcRepo, digest, dstRepo, digest, false); err != nil { return 0, err