backend: Unify backend construction using factory and registry
This unified construction removes most backend-specific code from global.go. The backend registry will also enable integration tests to use custom backends if necessary.
This commit is contained in:
parent
56836364a4
commit
7d12c29286
16 changed files with 235 additions and 142 deletions
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/limiter"
|
||||
"github.com/restic/restic/internal/backend/location"
|
||||
"github.com/restic/restic/internal/backend/rest"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
|
@ -36,6 +37,10 @@ type Backend struct {
|
|||
conn *StdioConn
|
||||
}
|
||||
|
||||
func NewFactory() location.Factory {
|
||||
return location.NewLimitedBackendFactory(ParseConfig, location.NoPassword, Create, Open)
|
||||
}
|
||||
|
||||
// run starts command with args and initializes the StdioConn.
|
||||
func run(command string, args ...string) (*StdioConn, *sync.WaitGroup, chan struct{}, func() error, error) {
|
||||
cmd := exec.Command(command, args...)
|
||||
|
@ -283,8 +288,8 @@ func Open(ctx context.Context, cfg Config, lim limiter.Limiter) (*Backend, error
|
|||
}
|
||||
|
||||
// Create initializes a new restic repo with rclone.
|
||||
func Create(ctx context.Context, cfg Config) (*Backend, error) {
|
||||
be, err := newBackend(ctx, cfg, nil)
|
||||
func Create(ctx context.Context, cfg Config, lim limiter.Limiter) (*Backend, error) {
|
||||
be, err := newBackend(ctx, cfg, lim)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue