From 9e508f0dfe08d461335015b4b7283ba4eab44a7b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 18 May 2015 17:38:22 -0700 Subject: [PATCH] Add windows related path handling, now recursive cp, sync works properly --- common-methods.go | 2 +- pkg/client/s3/s3.go | 6 +++--- pkg/client/url.go | 46 ++++++++++++++++++++++++++------------------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/common-methods.go b/common-methods.go index 90fabb40..86709d11 100644 --- a/common-methods.go +++ b/common-methods.go @@ -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) } diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 59446b4f..1eebf9ca 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -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 diff --git a/pkg/client/url.go b/pkg/client/url.go index fcd3413d..b3f1bf7a 100644 --- a/pkg/client/url.go +++ b/pkg/client/url.go @@ -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() }