mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-24 03:05:39 +01:00
Make sure the tag filter have the same behavior for empty value and *
Fixes #11233, make sure the tag filter have the same behavior for empty value and * Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
7ad3b500ac
commit
e4d42deb75
@ -415,18 +415,33 @@ func (c *controller) copyDeeply(ctx context.Context, srcRepo, reference, dstRepo
|
||||
digest := srcArt.Digest
|
||||
|
||||
// check the existence of artifact in the destination repository
|
||||
dstArt, err := c.GetByReference(ctx, dstRepo, digest, option)
|
||||
if err == nil {
|
||||
// return conflict error if the root parent artifact already exists under the destination repository
|
||||
if isRoot {
|
||||
if isRoot {
|
||||
// for the root artifact, check the existence by calling "Count()"
|
||||
// which finds the artifact based on all parent artifacts to avoid
|
||||
// the issue: https://github.com/goharbor/harbor/issues/11222
|
||||
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)
|
||||
}
|
||||
// the child artifact already under the destination repository, skip
|
||||
return dstArt.ID, nil
|
||||
}
|
||||
if !errors.IsErr(err, errors.NotFoundCode) {
|
||||
return 0, err
|
||||
} 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
|
||||
}
|
||||
if !errors.IsErr(err, errors.NotFoundCode) {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
// the artifact doesn't exist under the destination repository, continue to copy
|
||||
|
@ -414,6 +414,7 @@ func (c *controllerTestSuite) TestCopy() {
|
||||
RepositoryID: 1,
|
||||
Name: "library/hello-world",
|
||||
}, nil)
|
||||
c.artMgr.On("Count").Return(0, nil)
|
||||
c.artMgr.On("GetByDigest").Return(nil, errors.NotFoundError(nil))
|
||||
c.tagCtl.On("List").Return([]*tag.Tag{
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user