瀏覽代碼

If container does not exist try to remove the name and continue

Michael Crosby 11 年之前
父節點
當前提交
7bf3a07371
共有 1 個文件被更改,包括 18 次插入4 次删除
  1. 18 4
      runtime.go

+ 18 - 4
runtime.go

@@ -425,12 +425,26 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
 
 	// Set the enitity in the graph using the default name specified
 	if _, err := runtime.containerGraph.Set(name, id); err != nil {
-		if strings.HasSuffix(err.Error(), "name are not unique") {
-			conflictingContainer, _ := runtime.GetByName(name)
+		if !strings.HasSuffix(err.Error(), "name are not unique") {
+			return nil, nil, err
+		}
+
+		conflictingContainer, err := runtime.GetByName(name)
+		if err != nil {
+			if strings.Contains(err.Error(), "Could not find entity") {
+				return nil, nil, err
+			}
+
+			// Remove name and continue starting the container
+			if err := runtime.containerGraph.Delete(name); err != nil {
+				return nil, nil, err
+			}
+		} else {
 			nameAsKnownByUser := strings.TrimPrefix(name, "/")
-			return nil, nil, fmt.Errorf("Conflict, The name %s is already assigned to %s. You have to delete (or rename) that container to be able to assign %s to a container again.", nameAsKnownByUser, utils.TruncateID(conflictingContainer.ID), nameAsKnownByUser)
+			return nil, nil, fmt.Errorf(
+				"Conflict, The name %s is already assigned to %s. You have to delete (or rename) that container to be able to assign %s to a container again.", nameAsKnownByUser,
+				utils.TruncateID(conflictingContainer.ID), nameAsKnownByUser)
 		}
-		return nil, nil, err
 	}
 
 	// Generate default hostname