daemon/layer_store: Use named return error for defer

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-12-17 11:31:08 +01:00
parent 3fdde529e7
commit 26bb1af7e6

View File

@@ -645,7 +645,7 @@ func (ls *layerStore) saveMount(mount *mountedLayer) error {
return nil
}
func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit, storageOpt map[string]string) (string, error) {
func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit, storageOpt map[string]string) (_ string, retErr error) {
// Use "<graph-id>-init" to maintain compatibility with graph drivers
// which are expecting this layer with this special name. If all
// graph drivers can be updated to not rely on knowing about this layer
@@ -662,9 +662,8 @@ func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc Mou
}
// Clean up init layer if any subsequent operation fails
successful := false
defer func() {
if !successful {
if retErr != nil {
if err := ls.driver.Remove(initID); err != nil {
log.G(context.TODO()).WithFields(log.Fields{"init-id": initID, "error": err}).Error("Failed to clean up init layer after error")
}
@@ -685,7 +684,6 @@ func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc Mou
return "", err
}
successful = true
return initID, nil
}