diff --git a/cmd-common.go b/cmd-common.go index 68a73b73..114168b1 100644 --- a/cmd-common.go +++ b/cmd-common.go @@ -64,7 +64,7 @@ func getNewClient(u *parsedURL, debug bool) (clnt client.Client, err error) { return nil, iodine.New(errInvalidArgument{}, nil) } switch u.scheme { - case urlObjectStorage: // Minio and S3 compatible object storage + case urlS3: // Minio and S3 compatible object storage hostCfg, err := getHostConfig(u.String()) if err != nil { return nil, iodine.New(err, nil) @@ -79,7 +79,7 @@ func getNewClient(u *parsedURL, debug bool) (clnt client.Client, err error) { } clnt = s3.GetNewClient(u.String(), auth, mcUserAgent, debug) return clnt, nil - case urlFile: + case urlFS: clnt = fs.GetNewClient(u.String()) return clnt, nil default: diff --git a/cmd-ls.go b/cmd-ls.go index 6dbd286c..910efb2e 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -78,7 +78,7 @@ func doListCmd(ctx *cli.Context) { } // ListBuckets() will not be called for fsClient() as its not needed. - if targetURLParser.bucketName == "" && targetURLParser.scheme != urlFile { + if targetURLParser.bucketName == "" && targetURLParser.scheme != urlFS { buckets, err := client.ListBuckets() if err != nil { log.Debug.Println(iodine.New(err, nil)) diff --git a/cmd-mb.go b/cmd-mb.go index ed438825..aa742ea0 100644 --- a/cmd-mb.go +++ b/cmd-mb.go @@ -43,7 +43,7 @@ func doMakeBucketCmd(ctx *cli.Context) { // this is handled differently since http based URLs cannot have // nested directories as buckets, buckets are a unique alphanumeric // name having subdirectories is only supported for fsClient - if targetURLParser.scheme != urlFile { + if targetURLParser.scheme != urlFS { if !client.IsValidBucketName(targetURLParser.bucketName) { log.Debug.Println(iodine.New(err, nil)) console.Fatalf("mc: Invalid bucket name: %s", targetURLParser.bucketName) diff --git a/url-parser.go b/url-parser.go index f419ec53..6a2437e3 100644 --- a/url-parser.go +++ b/url-parser.go @@ -17,6 +17,7 @@ package main import ( + "regexp" "runtime" "strings" @@ -30,9 +31,9 @@ import ( type urlType int const ( - urlUnknown urlType = iota // Unknown type - urlObjectStorage // Minio and S3 compatible object storage - urlFile // POSIX compatible file systems + urlUnknown urlType = iota // Unknown type + urlS3 // Minio and S3 compatible object storage + urlFS // POSIX compatible file systems ) type parsedURL struct { @@ -42,21 +43,33 @@ type parsedURL struct { objectName string } -func getURLType(scheme string) urlType { - switch scheme { - case "http": - fallthrough - case "https": - return urlObjectStorage - case "c": - fallthrough - case "file": - fallthrough - case "": - return urlFile - default: +// getURLType returns the type of URL. +func getURLType(urlStr string) urlType { + u, err := url.Parse(urlStr) + if err != nil { return urlUnknown } + + if u.Scheme == "http" || u.Scheme == "https" { + return urlS3 + } + + if u.Scheme == "file" { + return urlFS + } + + // MS Windows OS: Match drive letters + if runtime.GOOS == "windows" { + if regexp.MustCompile(`^[a-zA-Z]?$`).MatchString(u.Scheme) { + return urlFS + } + } + + if u.Scheme == "" { + return urlFS + } + + return urlUnknown } // url2Object converts URL to bucket and objectname @@ -99,7 +112,7 @@ func newURL(urlStr string) (*parsedURL, error) { bucketName, objectName := url2Object(u) parsedURL := &parsedURL{ url: u, - scheme: getURLType(u.Scheme), + scheme: getURLType(urlStr), bucketName: bucketName, objectName: objectName, } @@ -108,7 +121,7 @@ func newURL(urlStr string) (*parsedURL, error) { func (u *parsedURL) String() string { switch u.scheme { - case urlFile: + case urlFS: var p string switch runtime.GOOS { case "windows":