mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon: cleanup getting container logic
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
This commit is contained in:
parent
5e0e71bbe0
commit
73bc885b23
1 changed files with 5 additions and 8 deletions
|
@ -128,19 +128,16 @@ func (daemon *Daemon) Get(prefixOrName string) (*Container, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByName will match only an exact name provided; we ignore errors
|
// GetByName will match only an exact name provided; we ignore errors
|
||||||
containerByName, _ := daemon.GetByName(prefixOrName)
|
if containerByName, _ := daemon.GetByName(prefixOrName); containerByName != nil {
|
||||||
containerId, indexError := daemon.idIndex.Get(prefixOrName)
|
|
||||||
|
|
||||||
if containerByName != nil {
|
|
||||||
// prefix is an exact match to a full container Name
|
// prefix is an exact match to a full container Name
|
||||||
return containerByName, nil
|
return containerByName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if containerId != "" {
|
containerId, indexError := daemon.idIndex.Get(prefixOrName)
|
||||||
// prefix is a fuzzy match to a container ID
|
if indexError != nil {
|
||||||
return daemon.containers.Get(containerId), nil
|
return nil, indexError
|
||||||
}
|
}
|
||||||
return nil, indexError
|
return daemon.containers.Get(containerId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exists returns a true if a container of the specified ID or name exists,
|
// Exists returns a true if a container of the specified ID or name exists,
|
||||||
|
|
Loading…
Reference in a new issue