mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-06 00:03:38 +00:00
Compare commits
3 Commits
295c685bc4
...
67cb1ab99d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67cb1ab99d | ||
|
|
065ae50868 | ||
|
|
90bfd91c50 |
@@ -9,6 +9,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"regexp"
|
||||
|
||||
"github.com/ncw/swift/v2"
|
||||
)
|
||||
@@ -24,7 +25,7 @@ type SwiftStorage struct {
|
||||
}
|
||||
|
||||
// CreateSwiftStorage creates an OpenStack Swift storage object. storageURL is in the form of
|
||||
// `user@authURL/container/path?arg1=value1&arg2=value2``
|
||||
// `user@authURL/container/path?arg1=value1&arg2=value2`
|
||||
func CreateSwiftStorage(storageURL string, key string, threads int) (storage *SwiftStorage, err error) {
|
||||
|
||||
// This is the map to store all arguments
|
||||
@@ -42,13 +43,6 @@ func CreateSwiftStorage(storageURL string, key string, threads int) (storage *Sw
|
||||
}
|
||||
}
|
||||
|
||||
// Take out the user name if there is one
|
||||
if strings.Contains(storageURL, "@") {
|
||||
userAndURL := strings.Split(storageURL, "@")
|
||||
arguments["user"] = userAndURL[0]
|
||||
storageURL = userAndURL[1]
|
||||
}
|
||||
|
||||
// The version is used to split authURL and container/path
|
||||
versions := []string{"/v1/", "/v1.0/", "/v2/", "/v2.0/", "/v3/", "/v3.0/", "/v4/", "/v4.0/"}
|
||||
storageDir := ""
|
||||
@@ -60,6 +54,17 @@ func CreateSwiftStorage(storageURL string, key string, threads int) (storage *Sw
|
||||
}
|
||||
}
|
||||
|
||||
// Take out the user name if there is one
|
||||
if strings.Contains(storageURL, "@") {
|
||||
// Use regex to split the username and the rest of the URL
|
||||
lineRegex := regexp.MustCompile(`^(.+)@([^@]+)$`)
|
||||
match := lineRegex.FindStringSubmatch(storageURL)
|
||||
if match != nil {
|
||||
arguments["user"] = match[1]
|
||||
storageURL = match[2]
|
||||
}
|
||||
}
|
||||
|
||||
// If no container/path is specified, find them from the arguments
|
||||
if storageDir == "" {
|
||||
storageDir = arguments["storage_dir"]
|
||||
@@ -108,7 +113,7 @@ func CreateSwiftStorage(storageURL string, key string, threads int) (storage *Sw
|
||||
arguments["protocol"] = "https"
|
||||
}
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
|
||||
ctx := context.Background()
|
||||
|
||||
// Please refer to https://godoc.org/github.com/ncw/swift#Connection
|
||||
connection := swift.Connection{
|
||||
|
||||
Reference in New Issue
Block a user