Browse code

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

Fix image filter

Brian Goff authored on 2016/01/15 03:59:14
Showing 2 changed files
... ...
@@ -57,7 +57,6 @@ func (daemon *Daemon) Images(filterArgs, filter string, all bool) ([]*types.Imag
57 57
 			return nil, fmt.Errorf("Invalid filter 'dangling=%s'", imageFilters.Get("dangling"))
58 58
 		}
59 59
 	}
60
-
61 60
 	if danglingOnly {
62 61
 		allImages = daemon.imageStore.Heads()
63 62
 	} else {
... ...
@@ -124,6 +123,11 @@ func (daemon *Daemon) Images(filterArgs, filter string, all bool) ([]*types.Imag
124 124
 		}
125 125
 		if newImage.RepoDigests == nil && newImage.RepoTags == nil {
126 126
 			if all || len(daemon.imageStore.Children(id)) == 0 {
127
+
128
+				if imageFilters.Include("dangling") && !danglingOnly {
129
+					//dangling=false case, so dangling image is not needed
130
+					continue
131
+				}
127 132
 				if filter != "" { // skip images with no references if filtering by tag
128 133
 					continue
129 134
 				}
... ...
@@ -176,6 +176,15 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
176 176
 	out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
177 177
 	// Expect one dangling image
178 178
 	c.Assert(strings.Count(out, imageID), checker.Equals, 1)
179
+
180
+	out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=false")
181
+	//dangling=false would not include dangling images
182
+	c.Assert(out, checker.Not(checker.Contains), imageID)
183
+
184
+	out, _ = dockerCmd(c, "images")
185
+	//docker images still include dangling images
186
+	c.Assert(out, checker.Contains, imageID)
187
+
179 188
 }
180 189
 
181 190
 func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) {