Browse code

No need for container.Lock if rename same name

During the renaming of a container, no need to call `container.Lock()`
if `oldName == newName`.

This is a follow-up from #23360 (commit 88d1ee6c112d980a63c625389524047fea32e6d9)

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2016/06/25 02:55:48
Showing 1 changed files
... ...
@@ -33,13 +33,13 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
33 33
 	oldName = container.Name
34 34
 	oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
35 35
 
36
-	container.Lock()
37
-	defer container.Unlock()
38
-
39 36
 	if oldName == newName {
40 37
 		return fmt.Errorf("Renaming a container with the same name as its current name")
41 38
 	}
42 39
 
40
+	container.Lock()
41
+	defer container.Unlock()
42
+
43 43
 	if newName, err = daemon.reserveName(container.ID, newName); err != nil {
44 44
 		return fmt.Errorf("Error when allocating new name: %v", err)
45 45
 	}