Skip to content

Commit bfeeabe

Browse files
committed
3452: Filter Volumes by name if any of the names match
Signed-off-by: Manu Gupta <[email protected]>
1 parent df713a6 commit bfeeabe

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

cmd/nerdctl/volume/volume_list_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ func TestVolumeLsFilter(t *testing.T) {
270270
},
271271
{
272272
Description: "Retrieving name=volume1 and name=volume2",
273-
// FIXME: https://github.com/containerd/nerdctl/issues/3452
274-
// Nerdctl filter behavior is broken
275-
Require: nerdtest.Docker,
276273
Command: func(data test.Data, helpers test.Helpers) test.Command {
277274
return helpers.Command("volume", "ls", "--quiet", "--filter", "name="+data.Get("vol1"), "--filter", "name="+data.Get("vol2"))
278275
},

pkg/cmd/volume/list.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,28 @@ func volumeMatchesFilter(vol native.Volume, labelFilterFuncs []func(*map[string]
269269
return false
270270
}
271271
}
272-
for _, nameFilterFunc := range nameFilterFuncs {
273-
if !nameFilterFunc(vol.Name) {
274-
return false
275-
}
272+
273+
if !anyMatch(vol.Name, nameFilterFuncs) {
274+
return false
276275
}
276+
277277
for _, sizeFilterFunc := range sizeFilterFuncs {
278278
if !sizeFilterFunc(vol.Size) {
279279
return false
280280
}
281281
}
282+
282283
return true
283284
}
285+
286+
func anyMatch[T any](vol T, filters []func(T) bool) bool {
287+
if len(filters) == 0 {
288+
return true
289+
}
290+
for _, f := range filters {
291+
if f(vol) {
292+
return true
293+
}
294+
}
295+
return false
296+
}

0 commit comments

Comments
 (0)