diff --git a/backend/s3/config.go b/backend/s3/config.go index b65c77488..eed4cabe7 100644 --- a/backend/s3/config.go +++ b/backend/s3/config.go @@ -63,7 +63,7 @@ func ParseConfig(s string) (interface{}, error) { } cfg.Bucket = path[0] if len(path) > 1 { - cfg.Prefix = path[1] + cfg.Prefix = strings.TrimRight(path[1], "/") } else { cfg.Prefix = defaultPrefix } diff --git a/backend/s3/config_test.go b/backend/s3/config_test.go index 29f0509b4..63bc2c77e 100644 --- a/backend/s3/config_test.go +++ b/backend/s3/config_test.go @@ -21,6 +21,11 @@ var configTests = []struct { Bucket: "bucketname", Prefix: "prefix/directory", }}, + {"s3://eu-central-1/bucketname/prefix/directory/", Config{ + Endpoint: "eu-central-1", + Bucket: "bucketname", + Prefix: "prefix/directory", + }}, {"s3:eu-central-1/foobar", Config{ Endpoint: "eu-central-1", Bucket: "foobar", @@ -36,6 +41,11 @@ var configTests = []struct { Bucket: "foobar", Prefix: "prefix/directory", }}, + {"s3:eu-central-1/foobar/prefix/directory/", Config{ + Endpoint: "eu-central-1", + Bucket: "foobar", + Prefix: "prefix/directory", + }}, {"s3:https://hostname:9999/foobar", Config{ Endpoint: "hostname:9999", Bucket: "foobar", @@ -52,12 +62,24 @@ var configTests = []struct { Prefix: "restic", UseHTTP: true, }}, + {"s3:http://hostname:9999/foobar/", Config{ + Endpoint: "hostname:9999", + Bucket: "foobar", + Prefix: "", + UseHTTP: true, + }}, {"s3:http://hostname:9999/bucket/prefix/directory", Config{ Endpoint: "hostname:9999", Bucket: "bucket", Prefix: "prefix/directory", UseHTTP: true, }}, + {"s3:http://hostname:9999/bucket/prefix/directory/", Config{ + Endpoint: "hostname:9999", + Bucket: "bucket", + Prefix: "prefix/directory", + UseHTTP: true, + }}, } func TestParseConfig(t *testing.T) {