mirror of
https://github.com/containers/podman.git
synced 2025-07-30 20:02:37 +08:00
Drop image.DecomposeString, make image.Parts private imageParts again
Now that DecomposeString has no users, make the type private again. Any new users of it should come with a rationale - and new users of the "none"/"latest" handling of untagged/digested names that is currently implemented should have an exceptionaly unusual rationale. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
@ -25,7 +25,7 @@ import (
|
||||
"github.com/containers/libpod/pkg/util"
|
||||
"github.com/containers/storage"
|
||||
"github.com/containers/storage/pkg/reexec"
|
||||
"github.com/opencontainers/go-digest"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -460,7 +460,7 @@ func normalizeTag(tag string) (string, error) {
|
||||
}
|
||||
// If the input does not have a tag, we need to add one (latest)
|
||||
if !decomposedTag.isTagged {
|
||||
tag = fmt.Sprintf("%s:%s", tag, decomposedTag.Tag)
|
||||
tag = fmt.Sprintf("%s:%s", tag, decomposedTag.tag)
|
||||
}
|
||||
// If the input doesn't specify a registry, set the registry to localhost
|
||||
if !decomposedTag.hasRegistry {
|
||||
@ -937,7 +937,7 @@ func (i *Image) MatchRepoTag(input string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if dcRepoName.Registry == dcImage.Registry && dcImage.Registry != "" {
|
||||
if dcRepoName.registry == dcImage.registry && dcImage.registry != "" {
|
||||
count++
|
||||
}
|
||||
if dcRepoName.name == dcImage.name && dcImage.name != "" {
|
||||
@ -945,7 +945,7 @@ func (i *Image) MatchRepoTag(input string) (string, error) {
|
||||
} else if splitString(dcRepoName.name) == splitString(dcImage.name) {
|
||||
count++
|
||||
}
|
||||
if dcRepoName.Tag == dcImage.Tag {
|
||||
if dcRepoName.tag == dcImage.tag {
|
||||
count++
|
||||
}
|
||||
results[count] = append(results[count], repoName)
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
"github.com/containers/image/docker/reference"
|
||||
)
|
||||
|
||||
// Parts describes the parts of an image's name
|
||||
type Parts struct {
|
||||
// imageParts describes the parts of an image's name
|
||||
type imageParts struct {
|
||||
transport string
|
||||
Registry string
|
||||
registry string
|
||||
name string
|
||||
Tag string
|
||||
tag string
|
||||
isTagged bool
|
||||
hasRegistry bool
|
||||
}
|
||||
@ -34,16 +34,10 @@ func GetImageBaseName(input string) (string, error) {
|
||||
return splitImageName[len(splitImageName)-1], nil
|
||||
}
|
||||
|
||||
// DecomposeString decomposes a string name into imageParts description. This
|
||||
// is a wrapper for decompose
|
||||
func DecomposeString(input string) (Parts, error) {
|
||||
return decompose(input)
|
||||
}
|
||||
|
||||
// decompose breaks an input name into an imageParts description
|
||||
func decompose(input string) (Parts, error) {
|
||||
func decompose(input string) (imageParts, error) {
|
||||
var (
|
||||
parts Parts
|
||||
parts imageParts
|
||||
hasRegistry bool
|
||||
tag string
|
||||
)
|
||||
@ -62,7 +56,7 @@ func decompose(input string) (Parts, error) {
|
||||
}
|
||||
registry := reference.Domain(imgRef.(reference.Named))
|
||||
imageName := reference.Path(imgRef.(reference.Named))
|
||||
// Is this a Registry or a repo?
|
||||
// Is this a registry or a repo?
|
||||
if isRegistry(registry) {
|
||||
hasRegistry = true
|
||||
} else {
|
||||
@ -71,27 +65,27 @@ func decompose(input string) (Parts, error) {
|
||||
registry = ""
|
||||
}
|
||||
}
|
||||
return Parts{
|
||||
Registry: registry,
|
||||
return imageParts{
|
||||
registry: registry,
|
||||
hasRegistry: hasRegistry,
|
||||
name: imageName,
|
||||
Tag: tag,
|
||||
tag: tag,
|
||||
isTagged: isTagged,
|
||||
transport: DefaultTransport,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// assemble concatenates an image's parts into a string
|
||||
func (ip *Parts) assemble() string {
|
||||
spec := fmt.Sprintf("%s:%s", ip.name, ip.Tag)
|
||||
func (ip *imageParts) assemble() string {
|
||||
spec := fmt.Sprintf("%s:%s", ip.name, ip.tag)
|
||||
|
||||
if ip.Registry != "" {
|
||||
spec = fmt.Sprintf("%s/%s", ip.Registry, spec)
|
||||
if ip.registry != "" {
|
||||
spec = fmt.Sprintf("%s/%s", ip.registry, spec)
|
||||
}
|
||||
return spec
|
||||
}
|
||||
|
||||
// assemble concatenates an image's parts with transport into a string
|
||||
func (ip *Parts) assembleWithTransport() string {
|
||||
func (ip *imageParts) assembleWithTransport() string {
|
||||
return fmt.Sprintf("%s%s", ip.transport, ip.assemble())
|
||||
}
|
||||
|
@ -55,9 +55,9 @@ func TestDecompose(t *testing.T) {
|
||||
} else {
|
||||
assert.NoError(t, err, c.input)
|
||||
assert.Equal(t, c.transport, parts.transport, c.input)
|
||||
assert.Equal(t, c.registry, parts.Registry, c.input)
|
||||
assert.Equal(t, c.registry, parts.registry, c.input)
|
||||
assert.Equal(t, c.name, parts.name, c.input)
|
||||
assert.Equal(t, c.tag, parts.Tag, c.input)
|
||||
assert.Equal(t, c.tag, parts.tag, c.input)
|
||||
assert.Equal(t, c.isTagged, parts.isTagged, c.input)
|
||||
assert.Equal(t, c.hasRegistry, parts.hasRegistry, c.input)
|
||||
assert.Equal(t, c.assembled, parts.assemble(), c.input)
|
||||
|
@ -76,7 +76,7 @@ func (ir *Runtime) getPullRefPair(srcRef types.ImageReference, destName string)
|
||||
decomposedDest, err := decompose(destName)
|
||||
if err == nil && !decomposedDest.hasRegistry {
|
||||
// If the image doesn't have a registry, set it as the default repo
|
||||
decomposedDest.Registry = DefaultLocalRegistry
|
||||
decomposedDest.registry = DefaultLocalRegistry
|
||||
decomposedDest.hasRegistry = true
|
||||
destName = decomposedDest.assemble()
|
||||
}
|
||||
@ -317,7 +317,7 @@ func (ir *Runtime) pullGoalFromPossiblyUnqualifiedName(inputName string) (*pullG
|
||||
}
|
||||
var refPairs []pullRefPair
|
||||
for _, registry := range searchRegistries {
|
||||
decomposedImage.Registry = registry
|
||||
decomposedImage.registry = registry
|
||||
imageName := decomposedImage.assembleWithTransport()
|
||||
if hasShaInInputName(inputName) {
|
||||
imageName = fmt.Sprintf("%s%s/%s", decomposedImage.transport, registry, inputName)
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
|
||||
// findImageInRepotags takes an imageParts struct and searches images' repotags for
|
||||
// a match on name:tag
|
||||
func findImageInRepotags(search Parts, images []*Image) (*storage.Image, error) {
|
||||
func findImageInRepotags(search imageParts, images []*Image) (*storage.Image, error) {
|
||||
var results []*storage.Image
|
||||
for _, image := range images {
|
||||
for _, name := range image.Names() {
|
||||
@ -25,12 +25,12 @@ func findImageInRepotags(search Parts, images []*Image) (*storage.Image, error)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if d.name == search.name && d.Tag == search.Tag {
|
||||
if d.name == search.name && d.tag == search.tag {
|
||||
results = append(results, image.image)
|
||||
continue
|
||||
}
|
||||
// account for registry:/somedir/image
|
||||
if strings.HasSuffix(d.name, search.name) && d.Tag == search.Tag {
|
||||
if strings.HasSuffix(d.name, search.name) && d.tag == search.tag {
|
||||
results = append(results, image.image)
|
||||
continue
|
||||
}
|
||||
|
Reference in New Issue
Block a user