From 73bc885b23fb06b6d9d6cb554fde93fe0e6bcb98 Mon Sep 17 00:00:00 2001 From: Ma Shimiao Date: Tue, 9 Jun 2015 13:47:31 +0800 Subject: [PATCH] daemon: cleanup getting container logic Signed-off-by: Ma Shimiao --- daemon/daemon.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 7356cfde69..92a586e199 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -128,19 +128,16 @@ func (daemon *Daemon) Get(prefixOrName string) (*Container, error) { } // GetByName will match only an exact name provided; we ignore errors - containerByName, _ := daemon.GetByName(prefixOrName) - containerId, indexError := daemon.idIndex.Get(prefixOrName) - - if containerByName != nil { + if containerByName, _ := daemon.GetByName(prefixOrName); containerByName != nil { // prefix is an exact match to a full container Name return containerByName, nil } - if containerId != "" { - // prefix is a fuzzy match to a container ID - return daemon.containers.Get(containerId), nil + containerId, indexError := daemon.idIndex.Get(prefixOrName) + if indexError != 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,