podman-images: return correct image list

Return and print the correct list of images by adding all specified
RepoTags to one image object, and priting them separately in
repository:repotag pairs.

Signed-off-by: Valentin Rothberg <vrothberg@suse.com>

Closes: #477
Approved by: rhatdan
This commit is contained in:
Valentin Rothberg 2018-03-12 19:07:07 +01:00 committed by Atomic Bot
parent 3fe87b011d
commit 9b2f81b07b
2 changed files with 23 additions and 14 deletions

View File

@ -182,15 +182,20 @@ func getImagesTemplateOutput(runtime *libpod.Runtime, images []inspect.ImageResu
if !opts.noTrunc { if !opts.noTrunc {
imageID = shortID(img.ID) imageID = shortID(img.ID)
} }
params := imagesTemplateParams{ // get all specified repo:tag pairs and print them separately
Repository: img.Repository, for repo, tags := range libpod.ReposToMap(img.RepoTags) {
Tag: img.Tag, for _, tag := range tags {
ID: imageID, params := imagesTemplateParams{
Digest: img.Digest, Repository: repo,
Created: units.HumanDuration(time.Since((createdTime))) + " ago", Tag: tag,
Size: units.HumanSizeWithPrecision(float64(*img.Size), 3), ID: imageID,
Digest: img.Digest,
Created: units.HumanDuration(time.Since((createdTime))) + " ago",
Size: units.HumanSizeWithPrecision(float64(*img.Size), 3),
}
imagesOutput = append(imagesOutput, params)
}
} }
imagesOutput = append(imagesOutput, params)
} }
return return
} }

View File

@ -1298,9 +1298,11 @@ func imageSize(img types.ImageSource) *uint64 {
return nil return nil
} }
func reposToMap(repotags []string) map[string]string { // ReposToMap parses the specified repotags and returns a map with repositories
// as keys and the corresponding arrays of tags as values.
func ReposToMap(repotags []string) map[string][]string {
// map format is repo -> tag // map format is repo -> tag
repos := make(map[string]string) repos := make(map[string][]string)
for _, repo := range repotags { for _, repo := range repotags {
var repository, tag string var repository, tag string
if len(repo) > 0 { if len(repo) > 0 {
@ -1308,10 +1310,10 @@ func reposToMap(repotags []string) map[string]string {
repository = repo[0:li] repository = repo[0:li]
tag = repo[li+1:] tag = repo[li+1:]
} }
repos[repository] = tag repos[repository] = append(repos[repository], tag)
} }
if len(repos) == 0 { if len(repos) == 0 {
repos["<none>"] = "<none" repos["<none>"] = []string{"<none>"}
} }
return repos return repos
} }
@ -1348,18 +1350,20 @@ func (r *Runtime) GetImageResults() ([]inspect.ImageResult, error) {
dangling = true dangling = true
} }
for repo, tag := range reposToMap(image.Names) { for repo, tags := range ReposToMap(image.Names) {
// use the first pair as the image's default repo and tag
results = append(results, inspect.ImageResult{ results = append(results, inspect.ImageResult{
ID: image.ID, ID: image.ID,
Repository: repo, Repository: repo,
RepoTags: image.Names, RepoTags: image.Names,
Tag: tag, Tag: tags[0],
Size: imageSize(img), Size: imageSize(img),
Digest: image.Digest, Digest: image.Digest,
Created: image.Created, Created: image.Created,
Labels: imgInspect.Labels, Labels: imgInspect.Labels,
Dangling: dangling, Dangling: dangling,
}) })
break
} }
} }