Skip to content

Commit

Permalink
imagefilter dangling handling corrected
Browse files Browse the repository at this point in the history
imagefilter dangling=<value> shall not be ignored.
this PR handles the value and returns images accordingly.

Signed-off-by: Kunal Kushwaha <[email protected]>
  • Loading branch information
kunalkushwaha committed Apr 11, 2019
1 parent 60ef8f8 commit 034cc8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cmd/podman/imagefilters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ func CreatedAfterFilter(createTime time.Time) ResultFilter {
}

// DanglingFilter allows you to filter images for dangling images
func DanglingFilter() ResultFilter {
func DanglingFilter(danglingImages bool) ResultFilter {
return func(i *adapter.ContainerImage) bool {
return i.Dangling()
if danglingImages {
return i.Dangling()
}
return !i.Dangling()
}
}

Expand Down
10 changes: 9 additions & 1 deletion cmd/podman/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -359,6 +360,9 @@ func CreateFilterFuncs(ctx context.Context, r *adapter.LocalRuntime, filters []s
var filterFuncs []imagefilters.ResultFilter
for _, filter := range filters {
splitFilter := strings.Split(filter, "=")
if len(splitFilter) != 2 {
return nil, errors.Errorf("invalid filter syntax %s", filter)
}
switch splitFilter[0] {
case "before":
before, err := r.NewImageFromLocal(splitFilter[1])
Expand All @@ -373,7 +377,11 @@ func CreateFilterFuncs(ctx context.Context, r *adapter.LocalRuntime, filters []s
}
filterFuncs = append(filterFuncs, imagefilters.CreatedAfterFilter(after.Created()))
case "dangling":
filterFuncs = append(filterFuncs, imagefilters.DanglingFilter())
danglingImages, err := strconv.ParseBool(splitFilter[1])
if err != nil {
return nil, errors.Wrapf(err, "invalid filter dangling=%s", splitFilter[1])
}
filterFuncs = append(filterFuncs, imagefilters.DanglingFilter(danglingImages))
case "label":
labelFilter := strings.Join(splitFilter[1:], "=")
filterFuncs = append(filterFuncs, imagefilters.LabelFilter(ctx, labelFilter))
Expand Down

0 comments on commit 034cc8a

Please sign in to comment.