Browse code

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

Michael Crosby authored on 2013/12/06 08:22:21
Showing 1 changed files
... ...
@@ -425,12 +425,26 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
425 425
 
426 426
 	// Set the enitity in the graph using the default name specified
427 427
 	if _, err := runtime.containerGraph.Set(name, id); err != nil {
428
-		if strings.HasSuffix(err.Error(), "name are not unique") {
429
-			conflictingContainer, _ := runtime.GetByName(name)
428
+		if !strings.HasSuffix(err.Error(), "name are not unique") {
429
+			return nil, nil, err
430
+		}
431
+
432
+		conflictingContainer, err := runtime.GetByName(name)
433
+		if err != nil {
434
+			if strings.Contains(err.Error(), "Could not find entity") {
435
+				return nil, nil, err
436
+			}
437
+
438
+			// Remove name and continue starting the container
439
+			if err := runtime.containerGraph.Delete(name); err != nil {
440
+				return nil, nil, err
441
+			}
442
+		} else {
430 443
 			nameAsKnownByUser := strings.TrimPrefix(name, "/")
431
-			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)
444
+			return nil, nil, fmt.Errorf(
445
+				"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,
446
+				utils.TruncateID(conflictingContainer.ID), nameAsKnownByUser)
432 447
 		}
433
-		return nil, nil, err
434 448
 	}
435 449
 
436 450
 	// Generate default hostname