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:
Michael Eischer
2023-06-08 13:04:34 +02:00
parent 56836364a4
commit 7d12c29286
16 changed files with 235 additions and 142 deletions

View File

@@ -10,6 +10,8 @@ import (
"github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/backend/layout"
"github.com/restic/restic/internal/backend/limiter"
"github.com/restic/restic/internal/backend/location"
"github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/fs"
@@ -28,6 +30,14 @@ type Local struct {
// ensure statically that *Local implements restic.Backend.
var _ restic.Backend = &Local{}
func NewFactory() location.Factory {
return location.NewLimitedBackendFactory(ParseConfig, location.NoPassword, func(ctx context.Context, cfg Config, _ limiter.Limiter) (*Local, error) {
return Create(ctx, cfg)
}, func(ctx context.Context, cfg Config, _ limiter.Limiter) (*Local, error) {
return Open(ctx, cfg)
})
}
const defaultLayout = "default"
func open(ctx context.Context, cfg Config) (*Local, error) {