mirror of
https://github.com/restic/restic.git
synced 2025-08-26 09:28:01 +00:00
backend, options: Prefer strings.Cut to SplitN
Also realigned the various "split into host🪣prefix"
implementations.
This commit is contained in:

committed by
Michael Eischer

parent
60aa87bbab
commit
65612d797c
@@ -42,17 +42,15 @@ func ParseConfig(s string) (interface{}, error) {
|
||||
|
||||
// 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 {
|
||||
bucket, prefix, colon := strings.Cut(s, ":")
|
||||
if !colon {
|
||||
return nil, errors.New("gs: invalid format: bucket name or path not found")
|
||||
}
|
||||
|
||||
bucket, path := data[0], path.Clean(data[1])
|
||||
|
||||
path = strings.TrimPrefix(path, "/")
|
||||
prefix = strings.TrimPrefix(path.Clean(prefix), "/")
|
||||
|
||||
cfg := NewConfig()
|
||||
cfg.Bucket = bucket
|
||||
cfg.Prefix = path
|
||||
cfg.Prefix = prefix
|
||||
return cfg, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user