diff --git a/cmd/restic/global.go b/cmd/restic/global.go index bf2efde70..8cae12907 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -768,9 +768,9 @@ func create(s string, opts options.Options) (restic.Backend, error) { case "b2": return b2.Create(globalOptions.ctx, cfg.(b2.Config), rt) case "rest": - return rest.Create(cfg.(rest.Config), rt) + return rest.Create(globalOptions.ctx, cfg.(rest.Config), rt) case "rclone": - return rclone.Create(cfg.(rclone.Config)) + return rclone.Create(globalOptions.ctx, cfg.(rclone.Config)) } debug.Log("invalid repository scheme: %v", s) diff --git a/internal/backend/rclone/backend.go b/internal/backend/rclone/backend.go index e18d8a998..2f730f238 100644 --- a/internal/backend/rclone/backend.go +++ b/internal/backend/rclone/backend.go @@ -275,8 +275,8 @@ func Open(cfg Config, lim limiter.Limiter) (*Backend, error) { return be, nil } -// Create initializes a new restic repo with clone. -func Create(cfg Config) (*Backend, error) { +// Create initializes a new restic repo with rclone. +func Create(ctx context.Context, cfg Config) (*Backend, error) { be, err := newBackend(cfg, nil) if err != nil { return nil, err @@ -294,7 +294,7 @@ func Create(cfg Config) (*Backend, error) { URL: url, } - restBackend, err := rest.Create(restConfig, debug.RoundTripper(be.tr)) + restBackend, err := rest.Create(ctx, restConfig, debug.RoundTripper(be.tr)) if err != nil { _ = be.Close() return nil, err diff --git a/internal/backend/rclone/backend_test.go b/internal/backend/rclone/backend_test.go index b7f3cebb4..0a8f91aea 100644 --- a/internal/backend/rclone/backend_test.go +++ b/internal/backend/rclone/backend_test.go @@ -1,6 +1,7 @@ package rclone_test import ( + "context" "os/exec" "testing" @@ -27,7 +28,7 @@ func newTestSuite(t testing.TB) *test.Suite { Create: func(config interface{}) (restic.Backend, error) { t.Logf("Create()") cfg := config.(rclone.Config) - be, err := rclone.Create(cfg) + be, err := rclone.Create(context.TODO(), cfg) if e, ok := errors.Cause(err).(*exec.Error); ok && e.Err == exec.ErrNotFound { t.Skipf("program %q not found", e.Name) return nil, nil diff --git a/internal/backend/rest/rest.go b/internal/backend/rest/rest.go index 6473a98b3..4dc271f38 100644 --- a/internal/backend/rest/rest.go +++ b/internal/backend/rest/rest.go @@ -63,13 +63,13 @@ func Open(cfg Config, rt http.RoundTripper) (*Backend, error) { } // Create creates a new REST on server configured in config. -func Create(cfg Config, rt http.RoundTripper) (*Backend, error) { +func Create(ctx context.Context, cfg Config, rt http.RoundTripper) (*Backend, error) { be, err := Open(cfg, rt) if err != nil { return nil, err } - _, err = be.Stat(context.TODO(), restic.Handle{Type: restic.ConfigFile}) + _, err = be.Stat(ctx, restic.Handle{Type: restic.ConfigFile}) if err == nil { return nil, errors.Fatal("config file already exists") } diff --git a/internal/backend/rest/rest_test.go b/internal/backend/rest/rest_test.go index 486f241a9..3f6859626 100644 --- a/internal/backend/rest/rest_test.go +++ b/internal/backend/rest/rest_test.go @@ -86,7 +86,7 @@ func newTestSuite(ctx context.Context, t testing.TB, url *url.URL, minimalData b // CreateFn is a function that creates a temporary repository for the tests. Create: func(config interface{}) (restic.Backend, error) { cfg := config.(rest.Config) - return rest.Create(cfg, tr) + return rest.Create(context.TODO(), cfg, tr) }, // OpenFn is a function that opens a previously created temporary repository.