forked from TrueCloudLab/restic
azure: Rework path initialization
This commit is contained in:
parent
d00fe95f10
commit
a726c91116
1 changed files with 15 additions and 15 deletions
|
@ -33,25 +33,25 @@ func init() {
|
||||||
// ParseConfig parses the string s and extracts the azure config. The
|
// ParseConfig parses the string s and extracts the azure config. The
|
||||||
// configuration format is azure:containerName:/[prefix].
|
// configuration format is azure:containerName:/[prefix].
|
||||||
func ParseConfig(s string) (interface{}, error) {
|
func ParseConfig(s string) (interface{}, error) {
|
||||||
if strings.HasPrefix(s, "azure:") {
|
if !strings.HasPrefix(s, "azure:") {
|
||||||
s = s[6:]
|
|
||||||
} else {
|
|
||||||
return nil, errors.New("azure: invalid format")
|
return nil, errors.New("azure: invalid format")
|
||||||
}
|
}
|
||||||
// use the first entry of the path as the container name and the
|
|
||||||
// remainder as prefix
|
|
||||||
path := strings.SplitN(s, ":/", 2)
|
|
||||||
return createConfig(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func createConfig(p []string) (interface{}, error) {
|
// strip prefix "azure:"
|
||||||
if len(p) < 2 {
|
s = s[6:]
|
||||||
return nil, errors.New("azure: invalid format, container name not found")
|
|
||||||
|
// use the first entry of the path as the bucket name and the
|
||||||
|
// remainder as prefix
|
||||||
|
data := strings.SplitN(s, ":", 2)
|
||||||
|
if len(data) < 2 {
|
||||||
|
return nil, errors.New("azure: invalid format: bucket name or path not found")
|
||||||
|
}
|
||||||
|
container, path := data[0], path.Clean(data[1])
|
||||||
|
if strings.HasPrefix(path, "/") {
|
||||||
|
path = path[1:]
|
||||||
}
|
}
|
||||||
cfg := NewConfig()
|
cfg := NewConfig()
|
||||||
cfg.Container = p[0]
|
cfg.Container = container
|
||||||
if p[1] != "" {
|
cfg.Prefix = path
|
||||||
cfg.Prefix = path.Clean(p[1])
|
|
||||||
}
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue