mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix before
and since
filter for docker ps
This fix tries to address the issue raised in 35931 where `before` and `since` filter for `docker ps` does not work and returns an error ``` Error response from daemon: no such container <container_name> ``` The issue was that `before` and `since` filter are matched with `view.Get()` which does not take into considerations of name match. This fix fixes the issue by adding additional logic for name match. This fix fixes 35931. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
39faf2a3a8
commit
9833332dba
1 changed files with 26 additions and 2 deletions
|
@ -302,7 +302,7 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis
|
||||||
var beforeContFilter, sinceContFilter *container.Snapshot
|
var beforeContFilter, sinceContFilter *container.Snapshot
|
||||||
|
|
||||||
err = psFilters.WalkValues("before", func(value string) error {
|
err = psFilters.WalkValues("before", func(value string) error {
|
||||||
beforeContFilter, err = view.Get(value)
|
beforeContFilter, err = idOrNameFilter(view, value)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -310,7 +310,7 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis
|
||||||
}
|
}
|
||||||
|
|
||||||
err = psFilters.WalkValues("since", func(value string) error {
|
err = psFilters.WalkValues("since", func(value string) error {
|
||||||
sinceContFilter, err = view.Get(value)
|
sinceContFilter, err = idOrNameFilter(view, value)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -364,6 +364,30 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis
|
||||||
names: view.GetAllNames(),
|
names: view.GetAllNames(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func idOrNameFilter(view container.View, value string) (*container.Snapshot, error) {
|
||||||
|
filter, err := view.Get(value)
|
||||||
|
switch err.(type) {
|
||||||
|
case container.NoSuchContainerError:
|
||||||
|
// Try name search instead
|
||||||
|
found := ""
|
||||||
|
for id, idNames := range view.GetAllNames() {
|
||||||
|
for _, eachName := range idNames {
|
||||||
|
if strings.TrimPrefix(value, "/") == strings.TrimPrefix(eachName, "/") {
|
||||||
|
if found != "" && found != id {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
found = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if found != "" {
|
||||||
|
filter, err = view.Get(found)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filter, err
|
||||||
|
}
|
||||||
|
|
||||||
func portOp(key string, filter map[nat.Port]bool) func(value string) error {
|
func portOp(key string, filter map[nat.Port]bool) func(value string) error {
|
||||||
return func(value string) error {
|
return func(value string) error {
|
||||||
if strings.Contains(value, ":") {
|
if strings.Contains(value, ":") {
|
||||||
|
|
Loading…
Add table
Reference in a new issue