From ba15bbc422a4f63d100240c6438c753379ea71e7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 28 Dec 2023 13:10:22 +0100 Subject: [PATCH] daemon/images: rename err-returns to prevent shadowing Prevent accidentally shadowing the error, which is used in a defer, and while at it, also fixed some linting warnings about unhandled errors. Signed-off-by: Sebastiaan van Stijn --- daemon/images/image_commit.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/daemon/images/image_commit.go b/daemon/images/image_commit.go index 27b7ea3fc0..1ac091ae96 100644 --- a/daemon/images/image_commit.go +++ b/daemon/images/image_commit.go @@ -78,14 +78,14 @@ func (i *ImageService) CommitImage(ctx context.Context, c backend.CommitConfig) return id, nil } -func exportContainerRw(layerStore layer.Store, id, mountLabel string) (arch io.ReadCloser, err error) { +func exportContainerRw(layerStore layer.Store, id, mountLabel string) (arch io.ReadCloser, retErr error) { rwlayer, err := layerStore.GetRWLayer(id) if err != nil { return nil, err } defer func() { - if err != nil { - layerStore.ReleaseRWLayer(rwlayer) + if retErr != nil { + _, _ = layerStore.ReleaseRWLayer(rwlayer) } }() @@ -93,23 +93,21 @@ func exportContainerRw(layerStore layer.Store, id, mountLabel string) (arch io.R // mount the layer if needed. But the Diff() function for windows requests that // the layer should be mounted when calling it. So we reserve this mount call // until windows driver can implement Diff() interface correctly. - _, err = rwlayer.Mount(mountLabel) - if err != nil { + if _, err := rwlayer.Mount(mountLabel); err != nil { return nil, err } archive, err := rwlayer.TarStream() if err != nil { - rwlayer.Unmount() + _ = rwlayer.Unmount() return nil, err } return ioutils.NewReadCloserWrapper(archive, func() error { - archive.Close() - err = rwlayer.Unmount() - layerStore.ReleaseRWLayer(rwlayer) - return err - }), - nil + _ = archive.Close() + err := rwlayer.Unmount() + _, _ = layerStore.ReleaseRWLayer(rwlayer) + return err + }), nil } // CommitBuildStep is used by the builder to create an image for each step in