Merge pull request #8941 from agonzalezro/log-duplicates

Log when truncindex.Get returns >1 container
This commit is contained in:
Jessie Frazelle 2015-01-06 10:41:19 -08:00
commit 84dc197b08
2 changed files with 15 additions and 4 deletions

View File

@ -151,12 +151,22 @@ 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 { var (
id string
err error
)
if id, err = daemon.idIndex.Get(name); err == nil {
return daemon.containers.Get(id) return daemon.containers.Get(id)
} }
if c, _ := daemon.GetByName(name); c != nil { if c, _ := daemon.GetByName(name); c != nil {
return c return c
} }
if err == truncindex.ErrDuplicateID {
log.Errorf("Short ID %s is ambiguous: please retry with more characters or use the full ID.\n", name)
}
return nil return nil
} }

View File

@ -11,8 +11,9 @@ import (
var ( var (
// ErrNoID is thrown when attempting to use empty prefixes // ErrNoID is thrown when attempting to use empty prefixes
ErrNoID = errors.New("prefix can't be empty") ErrNoID = errors.New("prefix can't be empty")
errDuplicateID = errors.New("multiple IDs were found") // ErrDuplicateID is thrown when a duplicated id was found
ErrDuplicateID = errors.New("multiple IDs were found")
) )
func init() { func init() {
@ -98,7 +99,7 @@ func (idx *TruncIndex) Get(s string) (string, error) {
if id != "" { if id != "" {
// we haven't found the ID if there are two or more IDs // we haven't found the ID if there are two or more IDs
id = "" id = ""
return errDuplicateID return ErrDuplicateID
} }
id = string(prefix) id = string(prefix)
return nil return nil