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 88d1ee6c11)

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-06-24 19:55:48 +02:00
parent 88d1ee6c11
commit 7e1ec8d2bd
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3

View file

@ -33,13 +33,13 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
oldName = container.Name
oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
container.Lock()
defer container.Unlock()
if oldName == newName {
return fmt.Errorf("Renaming a container with the same name as its current name")
}
container.Lock()
defer container.Unlock()
if newName, err = daemon.reserveName(container.ID, newName); err != nil {
return fmt.Errorf("Error when allocating new name: %v", err)
}