daemon: ContainerRename: use named error-return

It's used in various defers, but was using `err` as name, which can be
confusing, and increases the risk of accidentally shadowing the error.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
Albin Kerouanton 2023-11-07 13:54:01 +01:00
parent ea729aea4a
commit f5a611a74c
No known key found for this signature in database
GPG key ID: 630B8E1DCBDB1864

View file

@ -15,7 +15,7 @@ import (
// ContainerRename changes the name of a container, using the oldName
// to find the container. An error is returned if newName is already
// reserved.
func (daemon *Daemon) ContainerRename(oldName, newName string) error {
func (daemon *Daemon) ContainerRename(oldName, newName string) (retErr error) {
var (
sid string
sb *libnetwork.Sandbox
@ -65,7 +65,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
container.NetworkSettings.IsAnonymousEndpoint = false
defer func() {
if err != nil {
if retErr != nil {
container.Name = oldName
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
daemon.reserveName(container.ID, oldName)
@ -99,7 +99,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
}
defer func() {
if err != nil {
if retErr != nil {
container.Name = oldName
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
if e := container.CheckpointTo(daemon.containersReplica); e != nil {