Merge pull request #19326 from HackToday/19153-filter-rethink
Fix image filter
This commit is contained in:
commit
7cd6210a88
2 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue