mirror of
https://github.com/restic/restic.git
synced 2025-10-09 07:33:53 +00:00
backend: let ParseConfig return a Config pointer
In order to change the backend initialization in `global.go` to be able to generically call cfg.ApplyEnvironment() for supported backends, the `interface{}` returned by `ParseConfig` must contain a pointer to the configuration. An alternative would be to use reflection to convert the type from `interface{}(Config)` to `interface{}(*Config)` (from value to pointer type). However, this would just complicate the type mess further.
This commit is contained in:
@@ -29,10 +29,10 @@ func newAzureTestSuite(t testing.TB) *test.Suite[azure.Config] {
|
||||
MinimalData: true,
|
||||
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (azure.Config, error) {
|
||||
NewConfig: func() (*azure.Config, error) {
|
||||
cfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
||||
if err != nil {
|
||||
return azure.Config{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg.AccountName = os.Getenv("RESTIC_TEST_AZURE_ACCOUNT_NAME")
|
||||
@@ -150,7 +150,7 @@ func TestUploadLargeFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
be, err := azure.Create(ctx, cfg, tr)
|
||||
be, err := azure.Create(ctx, *cfg, tr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@@ -34,9 +34,9 @@ func init() {
|
||||
|
||||
// ParseConfig parses the string s and extracts the azure config. The
|
||||
// configuration format is azure:containerName:/[prefix].
|
||||
func ParseConfig(s string) (Config, error) {
|
||||
func ParseConfig(s string) (*Config, error) {
|
||||
if !strings.HasPrefix(s, "azure:") {
|
||||
return Config{}, errors.New("azure: invalid format")
|
||||
return nil, errors.New("azure: invalid format")
|
||||
}
|
||||
|
||||
// strip prefix "azure:"
|
||||
@@ -46,13 +46,13 @@ func ParseConfig(s string) (Config, error) {
|
||||
// remainder as prefix
|
||||
container, prefix, colon := strings.Cut(s, ":")
|
||||
if !colon {
|
||||
return Config{}, errors.New("azure: invalid format: bucket name or path not found")
|
||||
return nil, errors.New("azure: invalid format: bucket name or path not found")
|
||||
}
|
||||
prefix = strings.TrimPrefix(path.Clean(prefix), "/")
|
||||
cfg := NewConfig()
|
||||
cfg.Container = container
|
||||
cfg.Prefix = prefix
|
||||
return cfg, nil
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
// ApplyEnvironment saves values from the environment to the config.
|
||||
|
Reference in New Issue
Block a user