Merge pull request #19326 from HackToday/19153-filter-rethink

Fix image filter
This commit is contained in:
Brian Goff 2016-01-14 13:59:14 -05:00
commit 7cd6210a88
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) {