forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Solomon Hykes <[email protected]>
- Loading branch information
Showing
4 changed files
with
104 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package graph | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"path" | ||
"strings" | ||
|
||
"github.com/docker/docker/engine" | ||
"github.com/docker/docker/image" | ||
"github.com/docker/docker/pkg/parsers/filters" | ||
) | ||
|
||
func (s *TagStore) CmdImages(job *engine.Job) engine.Status { | ||
var ( | ||
allImages map[string]*image.Image | ||
err error | ||
filt_tagged = true | ||
) | ||
|
||
imageFilters, err := filters.FromParam(job.Getenv("filters")) | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
if i, ok := imageFilters["dangling"]; ok { | ||
for _, value := range i { | ||
if strings.ToLower(value) == "true" { | ||
filt_tagged = false | ||
} | ||
} | ||
} | ||
|
||
if job.GetenvBool("all") && filt_tagged { | ||
allImages, err = s.graph.Map() | ||
} else { | ||
allImages, err = s.graph.Heads() | ||
} | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
lookup := make(map[string]*engine.Env) | ||
s.Lock() | ||
for name, repository := range s.Repositories { | ||
if job.Getenv("filter") != "" { | ||
if match, _ := path.Match(job.Getenv("filter"), name); !match { | ||
continue | ||
} | ||
} | ||
for tag, id := range repository { | ||
image, err := s.graph.Get(id) | ||
if err != nil { | ||
log.Printf("Warning: couldn't load %s from %s/%s: %s", id, name, tag, err) | ||
continue | ||
} | ||
|
||
if out, exists := lookup[id]; exists { | ||
if filt_tagged { | ||
out.SetList("RepoTags", append(out.GetList("RepoTags"), fmt.Sprintf("%s:%s", name, tag))) | ||
} | ||
} else { | ||
// get the boolean list for if only the untagged images are requested | ||
delete(allImages, id) | ||
if filt_tagged { | ||
out := &engine.Env{} | ||
out.Set("ParentId", image.Parent) | ||
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)}) | ||
out.Set("Id", image.ID) | ||
out.SetInt64("Created", image.Created.Unix()) | ||
out.SetInt64("Size", image.Size) | ||
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size) | ||
lookup[id] = out | ||
} | ||
} | ||
|
||
} | ||
} | ||
s.Unlock() | ||
|
||
outs := engine.NewTable("Created", len(lookup)) | ||
for _, value := range lookup { | ||
outs.Add(value) | ||
} | ||
|
||
// Display images which aren't part of a repository/tag | ||
if job.Getenv("filter") == "" { | ||
for _, image := range allImages { | ||
out := &engine.Env{} | ||
out.Set("ParentId", image.Parent) | ||
out.SetList("RepoTags", []string{"<none>:<none>"}) | ||
out.Set("Id", image.ID) | ||
out.SetInt64("Created", image.Created.Unix()) | ||
out.SetInt64("Size", image.Size) | ||
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size) | ||
outs.Add(out) | ||
} | ||
} | ||
|
||
outs.ReverseSort() | ||
if _, err := outs.WriteListTo(job.Stdout); err != nil { | ||
return job.Error(err) | ||
} | ||
return engine.StatusOK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters