get URL type + win support
This commit is contained in:
+2
-2
@@ -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:
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
+31
-18
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user