mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-03 14:37:44 +01:00
Update the logic of copy artifact
1. Copy artifact will not return 409 anymore. 2. Make sure the tags of source artifact exist in the target artifact Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
db10720e80
commit
9bfabff4d2
@ -229,8 +229,6 @@ paths:
|
|||||||
$ref: '#/responses/403'
|
$ref: '#/responses/403'
|
||||||
'404':
|
'404':
|
||||||
$ref: '#/responses/404'
|
$ref: '#/responses/404'
|
||||||
'409':
|
|
||||||
$ref: '#/responses/409'
|
|
||||||
'500':
|
'500':
|
||||||
$ref: '#/responses/500'
|
$ref: '#/responses/500'
|
||||||
/projects/{project_name}/repositories/{repository_name}/artifacts/{reference}:
|
/projects/{project_name}/repositories/{repository_name}/artifacts/{reference}:
|
||||||
|
@ -118,8 +118,6 @@ func NewController() Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO concurrency summary
|
|
||||||
|
|
||||||
type controller struct {
|
type controller struct {
|
||||||
tagCtl tag.Controller
|
tagCtl tag.Controller
|
||||||
repoMgr repository.Manager
|
repoMgr repository.Manager
|
||||||
@ -415,33 +413,17 @@ func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo
|
|||||||
digest := srcArt.Digest
|
digest := srcArt.Digest
|
||||||
|
|
||||||
// check the existence of artifact in the destination repository
|
// check the existence of artifact in the destination repository
|
||||||
if isRoot {
|
dstArt, err := c.GetByReference(ctx, dstRepo, digest, option)
|
||||||
// for the root artifact, check the existence by calling "Count()"
|
if err == nil {
|
||||||
// which finds the artifact based on all parent artifacts to avoid
|
// the child artifact already exists under the destination repository, skip
|
||||||
// the issue: https://github.com/goharbor/harbor/issues/11222
|
if !isRoot {
|
||||||
n, err := c.artMgr.Count(ctx, &q.Query{
|
|
||||||
Keywords: map[string]interface{}{
|
|
||||||
"RepositoryName": dstRepo,
|
|
||||||
"Digest": digest,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
if n > 0 {
|
|
||||||
return 0, errors.New(nil).WithCode(errors.ConflictCode).
|
|
||||||
WithMessage("the artifact %s@%s already exists", dstRepo, digest)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// for the child artifact, check the existence by calling "GetByReference" directly
|
|
||||||
dstArt, err := c.GetByReference(ctx, dstRepo, digest, option)
|
|
||||||
if err == nil {
|
|
||||||
// the child artifact already under the destination repository, skip
|
|
||||||
return dstArt.ID, nil
|
return dstArt.ID, nil
|
||||||
}
|
}
|
||||||
if !errors.IsErr(err, errors.NotFoundCode) {
|
// the root parent already exists, goto next step to copy tags
|
||||||
return 0, err
|
goto tags
|
||||||
}
|
}
|
||||||
|
if !errors.IsErr(err, errors.NotFoundCode) {
|
||||||
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// the artifact doesn't exist under the destination repository, continue to copy
|
// the artifact doesn't exist under the destination repository, continue to copy
|
||||||
@ -457,6 +439,7 @@ func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tags:
|
||||||
// only copy the tags of outermost artifact
|
// only copy the tags of outermost artifact
|
||||||
var tags []string
|
var tags []string
|
||||||
for _, tag := range srcArt.Tags {
|
for _, tag := range srcArt.Tags {
|
||||||
|
Loading…
Reference in New Issue
Block a user