1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix image filter

This is related image fix for Propose #19153
for volume related change, would use another patch
to fix that.

Signed-off-by: Kai Qiang Wu(Kennan) <wkqwu@cn.ibm.com>
This commit is contained in:
Kai Qiang Wu(Kennan) 2016-01-14 06:58:31 +00:00
parent 742a7d53f2
commit 5ee69eb470
2 changed files with 14 additions and 1 deletions

View file

@ -57,7 +57,6 @@ func (daemon *Daemon) Images(filterArgs, filter string, all bool) ([]*types.Imag
return nil, fmt.Errorf("Invalid filter 'dangling=%s'", imageFilters.Get("dangling"))
}
}
if danglingOnly {
allImages = daemon.imageStore.Heads()
} else {
@ -124,6 +123,11 @@ func (daemon *Daemon) Images(filterArgs, filter string, all bool) ([]*types.Imag
}
if newImage.RepoDigests == nil && newImage.RepoTags == nil {
if all || len(daemon.imageStore.Children(id)) == 0 {
if imageFilters.Include("dangling") && !danglingOnly {
//dangling=false case, so dangling image is not needed
continue
}
if filter != "" { // skip images with no references if filtering by tag
continue
}

View file

@ -176,6 +176,15 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
// Expect one dangling image
c.Assert(strings.Count(out, imageID), checker.Equals, 1)
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=false")
//dangling=false would not include dangling images
c.Assert(out, checker.Not(checker.Contains), imageID)
out, _ = dockerCmd(c, "images")
//docker images still include dangling images
c.Assert(out, checker.Contains, imageID)
}
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) {