Browse Source

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

Michael Crosby 11 years ago
parent
commit
7bf3a07371
1 changed files with 18 additions and 4 deletions
  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
 	// Set the enitity in the graph using the default name specified
 	if _, err := runtime.containerGraph.Set(name, id); err != nil {
 	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, "/")
 			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
 	// Generate default hostname