mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Container name lookups to prefer IDs over names
Lookups of container names should prefer the ID over names assigned to containers by users. Signed-off-by: Eric Windisch <eric@windisch.us>
This commit is contained in:
parent
042b642d40
commit
231e07ded4
1 changed files with 4 additions and 7 deletions
|
@ -138,18 +138,15 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
|
||||||
// Get looks for a container by the specified ID or name, and returns it.
|
// Get looks for a container by the specified ID or name, and returns it.
|
||||||
// If the container is not found, or if an error occurs, nil is returned.
|
// If the container is not found, or if an error occurs, nil is returned.
|
||||||
func (daemon *Daemon) Get(name string) *Container {
|
func (daemon *Daemon) Get(name string) *Container {
|
||||||
|
if id, err := daemon.idIndex.Get(name); err == nil {
|
||||||
|
return daemon.containers.Get(id)
|
||||||
|
}
|
||||||
if c, _ := daemon.GetByName(name); c != nil {
|
if c, _ := daemon.GetByName(name); c != nil {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := daemon.idIndex.Get(name)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return daemon.containers.Get(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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,
|
||||||
// false otherwise.
|
// false otherwise.
|
||||||
func (daemon *Daemon) Exists(id string) bool {
|
func (daemon *Daemon) Exists(id string) bool {
|
||||||
|
|
Loading…
Add table
Reference in a new issue