diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-03-17 14:31:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-17 14:31:39 -0700 |
commit | b819f140016b239249287e73600f18ab78051d41 (patch) | |
tree | 85301f4082454156a864aba6b4b78745fb56a901 /pkg/bindings/images/build.go | |
parent | 3d7a8cf2af43a2d315fff7b8f74ae3d039f68dd0 (diff) | |
parent | 21f229a3dd3c1348d8f882050203d96f261f78ea (diff) | |
download | podman-b819f140016b239249287e73600f18ab78051d41.tar.gz podman-b819f140016b239249287e73600f18ab78051d41.tar.bz2 podman-b819f140016b239249287e73600f18ab78051d41.zip |
Merge pull request #9717 from nalind/error-race
[NO TESTS NEEDED] pkg/bindings/images.Build(): fix a race condition in error reporting
Diffstat (limited to 'pkg/bindings/images/build.go')
-rw-r--r-- | pkg/bindings/images/build.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 1cbd28c37..9d77883f9 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -20,6 +20,7 @@ import ( "github.com/containers/podman/v3/pkg/bindings" "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/storage/pkg/fileutils" + "github.com/containers/storage/pkg/ioutils" "github.com/docker/go-units" "github.com/hashicorp/go-multierror" jsoniter "github.com/json-iterator/go" @@ -252,7 +253,11 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO logrus.Errorf("cannot tar container entries %v error: %v", entries, err) return nil, err } - defer tarfile.Close() + defer func() { + if err := tarfile.Close(); err != nil { + logrus.Errorf("%v\n", err) + } + }() containerFile, err := filepath.Abs(entries[0]) if err != nil { @@ -340,7 +345,7 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { gw := gzip.NewWriter(pw) tw := tar.NewWriter(gw) - var merr error + var merr *multierror.Error go func() { defer pw.Close() defer gw.Close() @@ -421,7 +426,14 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { merr = multierror.Append(merr, err) } }() - return pr, merr + rc := ioutils.NewReadCloserWrapper(pr, func() error { + if merr != nil { + merr = multierror.Append(merr, pr.Close()) + return merr.ErrorOrNil() + } + return pr.Close() + }) + return rc, nil } func parseDockerignore(root string) ([]string, error) { |