forked from TrueCloudLab/restic
rest: use global context on repository creation
This commit is contained in:
parent
4b0fcaed45
commit
37a5e2d681
5 changed files with 10 additions and 9 deletions
|
@ -768,9 +768,9 @@ func create(s string, opts options.Options) (restic.Backend, error) {
|
||||||
case "b2":
|
case "b2":
|
||||||
return b2.Create(globalOptions.ctx, cfg.(b2.Config), rt)
|
return b2.Create(globalOptions.ctx, cfg.(b2.Config), rt)
|
||||||
case "rest":
|
case "rest":
|
||||||
return rest.Create(cfg.(rest.Config), rt)
|
return rest.Create(globalOptions.ctx, cfg.(rest.Config), rt)
|
||||||
case "rclone":
|
case "rclone":
|
||||||
return rclone.Create(cfg.(rclone.Config))
|
return rclone.Create(globalOptions.ctx, cfg.(rclone.Config))
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.Log("invalid repository scheme: %v", s)
|
debug.Log("invalid repository scheme: %v", s)
|
||||||
|
|
|
@ -275,8 +275,8 @@ func Open(cfg Config, lim limiter.Limiter) (*Backend, error) {
|
||||||
return be, nil
|
return be, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create initializes a new restic repo with clone.
|
// Create initializes a new restic repo with rclone.
|
||||||
func Create(cfg Config) (*Backend, error) {
|
func Create(ctx context.Context, cfg Config) (*Backend, error) {
|
||||||
be, err := newBackend(cfg, nil)
|
be, err := newBackend(cfg, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -294,7 +294,7 @@ func Create(cfg Config) (*Backend, error) {
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
|
|
||||||
restBackend, err := rest.Create(restConfig, debug.RoundTripper(be.tr))
|
restBackend, err := rest.Create(ctx, restConfig, debug.RoundTripper(be.tr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = be.Close()
|
_ = be.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package rclone_test
|
package rclone_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ func newTestSuite(t testing.TB) *test.Suite {
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(config interface{}) (restic.Backend, error) {
|
||||||
t.Logf("Create()")
|
t.Logf("Create()")
|
||||||
cfg := config.(rclone.Config)
|
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 {
|
if e, ok := errors.Cause(err).(*exec.Error); ok && e.Err == exec.ErrNotFound {
|
||||||
t.Skipf("program %q not found", e.Name)
|
t.Skipf("program %q not found", e.Name)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -63,13 +63,13 @@ func Open(cfg Config, rt http.RoundTripper) (*Backend, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new REST on server configured in config.
|
// 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)
|
be, err := Open(cfg, rt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err == nil {
|
||||||
return nil, errors.Fatal("config file already exists")
|
return nil, errors.Fatal("config file already exists")
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(config interface{}) (restic.Backend, error) {
|
||||||
cfg := config.(rest.Config)
|
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.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
|
|
Loading…
Reference in a new issue