From c934c99d4124d4033b7cbd99b79fc8ebe377d804 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 8 Apr 2023 11:59:44 +0200 Subject: [PATCH] gs: replace usage of context.Background() --- cmd/restic/global.go | 2 +- internal/backend/gs/gs.go | 3 +-- internal/backend/gs/gs_test.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 8d34f8ddb..537fe02fe 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -801,7 +801,7 @@ func create(ctx context.Context, s string, opts options.Options) (restic.Backend case "s3": be, err = s3.Create(ctx, cfg.(s3.Config), rt) case "gs": - be, err = gs.Create(cfg.(gs.Config), rt) + be, err = gs.Create(ctx, cfg.(gs.Config), rt) case "azure": be, err = azure.Create(ctx, cfg.(azure.Config), rt) case "swift": diff --git a/internal/backend/gs/gs.go b/internal/backend/gs/gs.go index f310fbef5..62e5c4954 100644 --- a/internal/backend/gs/gs.go +++ b/internal/backend/gs/gs.go @@ -124,14 +124,13 @@ func Open(cfg Config, rt http.RoundTripper) (restic.Backend, error) { // // The service account must have the "storage.buckets.create" permission to // create a bucket the does not yet exist. -func Create(cfg Config, rt http.RoundTripper) (restic.Backend, error) { +func Create(ctx context.Context, cfg Config, rt http.RoundTripper) (restic.Backend, error) { be, err := open(cfg, rt) if err != nil { return nil, errors.Wrap(err, "open") } // Try to determine if the bucket exists. If it does not, try to create it. - ctx := context.Background() exists, err := be.bucketExists(ctx, be.bucket) if err != nil { if e, ok := err.(*googleapi.Error); ok && e.Code == http.StatusForbidden { diff --git a/internal/backend/gs/gs_test.go b/internal/backend/gs/gs_test.go index 77f8986f1..19ae8b829 100644 --- a/internal/backend/gs/gs_test.go +++ b/internal/backend/gs/gs_test.go @@ -42,7 +42,7 @@ func newGSTestSuite(t testing.TB) *test.Suite { Create: func(config interface{}) (restic.Backend, error) { cfg := config.(gs.Config) - be, err := gs.Create(cfg, tr) + be, err := gs.Create(context.Background(), cfg, tr) if err != nil { return nil, err }