2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 23:06:32 +00:00

strip off the trailing slash for the object prefix

This commit is contained in:
Christian Kemper 2016-02-14 07:16:50 -08:00
parent 48f85fbb09
commit 74608531c7
2 changed files with 23 additions and 1 deletions

View File

@ -63,7 +63,7 @@ func ParseConfig(s string) (interface{}, error) {
} }
cfg.Bucket = path[0] cfg.Bucket = path[0]
if len(path) > 1 { if len(path) > 1 {
cfg.Prefix = path[1] cfg.Prefix = strings.TrimRight(path[1], "/")
} else { } else {
cfg.Prefix = defaultPrefix cfg.Prefix = defaultPrefix
} }

View File

@ -21,6 +21,11 @@ var configTests = []struct {
Bucket: "bucketname", Bucket: "bucketname",
Prefix: "prefix/directory", 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{ {"s3:eu-central-1/foobar", Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "foobar", Bucket: "foobar",
@ -36,6 +41,11 @@ var configTests = []struct {
Bucket: "foobar", Bucket: "foobar",
Prefix: "prefix/directory", 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{ {"s3:https://hostname:9999/foobar", Config{
Endpoint: "hostname:9999", Endpoint: "hostname:9999",
Bucket: "foobar", Bucket: "foobar",
@ -52,12 +62,24 @@ var configTests = []struct {
Prefix: "restic", Prefix: "restic",
UseHTTP: true, UseHTTP: true,
}}, }},
{"s3:http://hostname:9999/foobar/", Config{
Endpoint: "hostname:9999",
Bucket: "foobar",
Prefix: "",
UseHTTP: true,
}},
{"s3:http://hostname:9999/bucket/prefix/directory", Config{ {"s3:http://hostname:9999/bucket/prefix/directory", Config{
Endpoint: "hostname:9999", Endpoint: "hostname:9999",
Bucket: "bucket", Bucket: "bucket",
Prefix: "prefix/directory", Prefix: "prefix/directory",
UseHTTP: true, 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) { func TestParseConfig(t *testing.T) {