Merge pull request #642 from harshavardhana/pr_out_add_windows_related_path_handling_now_recursive_cp_sync_works_properly

This commit is contained in:
Harshavardhana
2015-05-18 17:40:09 -07:00
3 changed files with 31 additions and 23 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ func getNewClient(urlStr string, auth *hostConfig, debug bool) (clnt client.Clie
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
s3Config.HostURL = urlStr
s3Config.Debug = debug
return s3.New(s3Config), nil
return s3.New(s3Config)
case client.Filesystem:
return fs.New(urlStr)
}
+3 -3
View File
@@ -75,10 +75,10 @@ func getRegion(host string) string {
}
// New returns an initialized s3Client structure. if debug use a internal trace transport
func New(config *Config) client.Client {
func New(config *Config) (client.Client, error) {
u, err := url.Parse(config.HostURL)
if err != nil {
return nil
return nil, iodine.New(err, nil)
}
var transport http.RoundTripper
switch {
@@ -95,7 +95,7 @@ func New(config *Config) client.Client {
objectstorageConf.Region = getRegion(u.Host)
objectstorageConf.Endpoint = u.Scheme + "://" + u.Host
api := objectstorage.New(objectstorageConf)
return &s3Client{api: api, hostURL: u}
return &s3Client{api: api, hostURL: u}, nil
}
// GetObject - get object
+27 -19
View File
@@ -19,7 +19,8 @@ package client
import (
"bytes"
"net/url"
"os"
"runtime"
"strings"
)
// URL client url structure
@@ -35,29 +36,27 @@ type URLType int
// enum types
const (
Unknown URLType = iota // Unknown type
Object // Minio and S3 compatible object storage
Filesystem // POSIX compatible file systems
Object = iota // Minio and S3 compatible object storage
Filesystem // POSIX compatible file systems
)
// String converts type to string.
func (t URLType) String() string {
switch t {
case Object:
return "Object"
case Filesystem:
return "Filesystem"
default:
return "Unknown"
}
}
// Parse url parse
func Parse(urlStr string) *URL {
u, err := url.Parse(urlStr)
if err != nil {
return nil
}
if u.Opaque != "" {
path, err := url.QueryUnescape(u.Opaque)
if err != nil {
return nil
}
// if Opaque defaulting to filesystem
return &URL{
Type: Filesystem,
Path: path,
}
}
if u.Scheme == "http" || u.Scheme == "https" {
return &URL{
@@ -89,9 +88,18 @@ func (u *URL) String() string {
buf.WriteString(h)
}
}
if u.Path != "" && u.Path[0] != '/' && u.Host != "" {
buf.WriteByte(os.PathSeparator)
switch runtime.GOOS {
case "windows":
if u.Path != "" && u.Path[0] != '\\' && u.Host != "" {
buf.WriteByte('/')
}
buf.WriteString(strings.Replace(u.Path, "\\", "/", -1))
default:
if u.Path != "" && u.Path[0] != '/' && u.Host != "" {
buf.WriteByte('/')
}
buf.WriteString(u.Path)
}
buf.WriteString(u.Path)
return buf.String()
}