From 66682e5b250681be3fb39ab6098a02b5d5aad62c Mon Sep 17 00:00:00 2001 From: pa250194 Date: Tue, 2 Nov 2021 15:23:19 -0500 Subject: [PATCH] Fix: errgroup provides waitgroup within the Go function Signed-off-by: pa250194 --- pkg/gcp/gcp.go | 6 +----- pkg/minio/minio.go | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/gcp/gcp.go b/pkg/gcp/gcp.go index c92ffe198..69b275755 100644 --- a/pkg/gcp/gcp.go +++ b/pkg/gcp/gcp.go @@ -23,7 +23,6 @@ import ( "os" "path/filepath" "strings" - "sync" gcpstorage "cloud.google.com/go/storage" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" @@ -181,7 +180,6 @@ func (c *GCPClient) FGetObject(ctx context.Context, bucketName, objectName, loca func (c *GCPClient) ListObjects(ctx context.Context, matcher gitignore.Matcher, bucketName, tempDir string) error { log := logr.FromContext(ctx) items := c.Client.Bucket(bucketName).Objects(ctx, nil) - var wg sync.WaitGroup g, ctx := errgroup.WithContext(ctx) for { object, err := items.Next() @@ -193,9 +191,7 @@ func (c *GCPClient) ListObjects(ctx context.Context, matcher gitignore.Matcher, return err } if !(strings.HasSuffix(object.Name, "/") || object.Name == sourceignore.IgnoreFile || matcher.Match(strings.Split(object.Name, "/"), false)) { - wg.Add(1) g.Go(func() error { - defer wg.Done() if err := DownloadObject(ctx, c, object, matcher, bucketName, tempDir); err != nil { log.Error(err, fmt.Sprintf("Error downloading %s from bucket %s: ", object.Name, bucketName)) return err @@ -207,7 +203,6 @@ func (c *GCPClient) ListObjects(ctx context.Context, matcher gitignore.Matcher, if err := g.Wait(); err != nil { return err } - wg.Wait() return nil } @@ -219,6 +214,7 @@ func (c *GCPClient) Close(ctx context.Context) { } } +// ObjectIsNotFound checks if the error provided is ErrorObjectDoesNotExist(object does not exist) func (c *GCPClient) ObjectIsNotFound(err error) bool { return errors.Is(err, ErrorObjectDoesNotExist) } diff --git a/pkg/minio/minio.go b/pkg/minio/minio.go index 81e0a3654..64b11cce4 100644 --- a/pkg/minio/minio.go +++ b/pkg/minio/minio.go @@ -121,6 +121,7 @@ func (c *MinioClient) Close(ctx context.Context) { //minio client does not provide a close method } +// ObjectIsNotFound checks if the error provided is NoSuchKey(object does not exist) func (c *MinioClient) ObjectIsNotFound(err error) bool { resp, ok := err.(minio.ErrorResponse) return ok && resp.Code != "NoSuchKey"