mirror of
https://github.com/goharbor/harbor
synced 2025-05-18 06:39:32 +00:00
resolve copy failure for artifact with multiple accessories (#17123)
If the artifact has more than one signaure, it will currently copy the last one. After the fix, all accessories can be copied to the target project. Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
927f9f5af3
commit
6917021b41
@ -145,7 +145,7 @@ type controller struct {
|
|||||||
|
|
||||||
type ArtOption struct {
|
type ArtOption struct {
|
||||||
Tags []string
|
Tags []string
|
||||||
Accs []accessorymodel.AccessoryData
|
Accs []*accessorymodel.AccessoryData
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) Ensure(ctx context.Context, repository, digest string, option *ArtOption) (bool, int64, error) {
|
func (c *controller) Ensure(ctx context.Context, repository, digest string, option *ArtOption) (bool, int64, error) {
|
||||||
@ -457,7 +457,7 @@ func (c *controller) deleteDeeply(ctx context.Context, id int64, isRoot, isAcces
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) Copy(ctx context.Context, srcRepo, reference, dstRepo string) (int64, error) {
|
func (c *controller) Copy(ctx context.Context, srcRepo, reference, dstRepo string) (int64, error) {
|
||||||
dstAccs := make([]accessorymodel.AccessoryData, 0)
|
dstAccs := make([]*accessorymodel.AccessoryData, 0)
|
||||||
return c.copyDeeply(ctx, srcRepo, reference, dstRepo, true, false, &dstAccs)
|
return c.copyDeeply(ctx, srcRepo, reference, dstRepo, true, false, &dstAccs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +465,7 @@ func (c *controller) Copy(ctx context.Context, srcRepo, reference, dstRepo strin
|
|||||||
// this bypass our own logic(ensure, fire event, etc.) inside the registry handlers,
|
// this bypass our own logic(ensure, fire event, etc.) inside the registry handlers,
|
||||||
// these logic must be covered explicitly here.
|
// these logic must be covered explicitly here.
|
||||||
// "copyDeeply" iterates the child artifacts and copy them first
|
// "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) {
|
func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo string, isRoot, isAcc bool, dstAccs *[]*accessorymodel.AccessoryData) (int64, error) {
|
||||||
var option *Option
|
var option *Option
|
||||||
option = &Option{WithTag: true, WithAccessory: true}
|
option = &Option{WithTag: true, WithAccessory: true}
|
||||||
if isAcc {
|
if isAcc {
|
||||||
@ -503,17 +503,17 @@ func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo
|
|||||||
|
|
||||||
// copy accessory if contains any
|
// copy accessory if contains any
|
||||||
for _, acc := range srcArt.Accessories {
|
for _, acc := range srcArt.Accessories {
|
||||||
id, err := c.copyDeeply(ctx, srcRepo, acc.GetData().Digest, dstRepo, false, true, dstAccs)
|
dstAcc := &accessorymodel.AccessoryData{
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
dstAcc := accessorymodel.AccessoryData{
|
|
||||||
ArtifactID: id,
|
|
||||||
Digest: acc.GetData().Digest,
|
Digest: acc.GetData().Digest,
|
||||||
Type: acc.GetData().Type,
|
Type: acc.GetData().Type,
|
||||||
Size: acc.GetData().Size,
|
Size: acc.GetData().Size,
|
||||||
}
|
}
|
||||||
*dstAccs = append(*dstAccs, dstAcc)
|
*dstAccs = append(*dstAccs, dstAcc)
|
||||||
|
id, err := c.copyDeeply(ctx, srcRepo, acc.GetData().Digest, dstRepo, false, true, dstAccs)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
dstAcc.ArtifactID = id
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the parent artifact into the backend docker registry
|
// copy the parent artifact into the backend docker registry
|
||||||
@ -530,7 +530,9 @@ ensureArt:
|
|||||||
// ensure the parent artifact exist in the database
|
// ensure the parent artifact exist in the database
|
||||||
artopt := &ArtOption{
|
artopt := &ArtOption{
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Accs: *dstAccs,
|
}
|
||||||
|
if !isAcc {
|
||||||
|
artopt.Accs = *dstAccs
|
||||||
}
|
}
|
||||||
_, id, err := c.Ensure(ctx, dstRepo, digest, artopt)
|
_, id, err := c.Ensure(ctx, dstRepo, digest, artopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user