diff --git a/access-main.go b/access-main.go index 7e5901b4..c7b2f6fe 100644 --- a/access-main.go +++ b/access-main.go @@ -108,8 +108,7 @@ func mainAccess(ctx *cli.Context) { config := mustGetMcConfig() for _, arg := range ctx.Args().Tail() { - targetURL, err := getCanonicalizedURL(arg, config.Aliases) - fatalIf(err.Trace(arg), "Unable to parse argument ‘"+arg+"’.") + targetURL := aliasExpand(arg, config.Aliases) fatalIf(doUpdateAccessCmd(targetURL, perms).Trace(targetURL, string(perms)), "Unable to set access permission ‘"+string(perms)+"’ for ‘"+targetURL+"’.") diff --git a/aliases.go b/aliases.go index cc182074..a73d7332 100644 --- a/aliases.go +++ b/aliases.go @@ -44,7 +44,7 @@ func aliasExpand(aliasedURL string, aliases map[string]string) string { return aliasValue // exact match. } _, sepLen := utf8.DecodeRuneInString(splits[1]) - if sepLen == 1 && !os.IsPathSeparator(splits[1][0]) { + if sepLen == 1 && !os.IsPathSeparator(splits[1][0]) && splits[1] != recursiveSeparator { return aliasedURL // Do not expand for whole strings with alias prefix. } // Matched, but path needs to be joined. diff --git a/cat-main.go b/cat-main.go index a87b1407..c08e4c31 100644 --- a/cat-main.go +++ b/cat-main.go @@ -96,10 +96,7 @@ func mainCat(ctx *cli.Context) { func catURL(sourceURL string) *probe.Error { config := mustGetMcConfig() - URL, err := getCanonicalizedURL(sourceURL, config.Aliases) - if err != nil { - return err.Trace(sourceURL) - } + URL := aliasExpand(sourceURL, config.Aliases) sourceClnt, err := source2Client(URL) if err != nil { diff --git a/common-methods.go b/common-methods.go index e5a92d14..543d16d2 100644 --- a/common-methods.go +++ b/common-methods.go @@ -168,9 +168,6 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error) } func url2Client(url string) (client.Client, *probe.Error) { - if !isValidURL(url) { - return nil, errInvalidURL(url).Trace() - } urlconfig, err := getHostConfig(url) if err != nil { return nil, err.Trace(url) diff --git a/diff-main.go b/diff-main.go index f9d5324f..81374f95 100644 --- a/diff-main.go +++ b/diff-main.go @@ -81,11 +81,8 @@ func mainDiff(ctx *cli.Context) { firstArg := ctx.Args().First() secondArg := ctx.Args().Last() - firstURL, err := getCanonicalizedURL(firstArg, config.Aliases) - fatalIf(err.Trace(firstArg), "Unable to parse first argument ‘"+firstArg+"’.") - - secondURL, err := getCanonicalizedURL(secondArg, config.Aliases) - fatalIf(err.Trace(secondArg), "Unable to parse second argument ‘"+secondArg+"’.") + firstURL := aliasExpand(firstArg, config.Aliases) + secondURL := aliasExpand(secondArg, config.Aliases) newFirstURL := stripRecursiveURL(firstURL) for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) { diff --git a/hostconfig.go b/hostconfig.go index c9aee0d5..aa49dd4d 100644 --- a/hostconfig.go +++ b/hostconfig.go @@ -34,24 +34,22 @@ func getHostConfig(URL string) (hostConfig, *probe.Error) { if err != nil { return hostConfig{}, err.Trace() } - { - url := client.NewURL(URL) - // No host matching or keys needed for filesystem requests - if url.Type == client.Filesystem { - hostCfg := hostConfig{ - AccessKeyID: "", - SecretAccessKey: "", - } - return hostCfg, nil + url := client.NewURL(URL) + // No host matching or keys needed for filesystem requests + if url.Type == client.Filesystem { + hostCfg := hostConfig{ + AccessKeyID: "", + SecretAccessKey: "", } - for globURL, hostCfg := range config.Hosts { - match, err := filepath.Match(globURL, url.Host) - if err != nil { - return hostConfig{}, errInvalidGlobURL(globURL, URL).Trace() - } - if match { - return hostCfg, nil - } + return hostCfg, nil + } + for globURL, hostCfg := range config.Hosts { + match, err := filepath.Match(globURL, url.Host) + if err != nil { + return hostConfig{}, errInvalidGlobURL(globURL, URL).Trace() + } + if match { + return hostCfg, nil } } return hostConfig{}, errNoMatchingHost(URL).Trace() diff --git a/ls-main.go b/ls-main.go index 2d7aea68..076fbad6 100644 --- a/ls-main.go +++ b/ls-main.go @@ -110,11 +110,10 @@ func mainList(ctx *cli.Context) { config := mustGetMcConfig() for _, arg := range args { - targetURL, err := getCanonicalizedURL(arg, config.Aliases) - fatalIf(err.Trace(arg), "Unable to parse argument ‘"+arg+"’.") + targetURL := aliasExpand(arg, config.Aliases) // if recursive strip off the "..." - err = doListCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL)) + err := doListCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL)) fatalIf(err.Trace(targetURL), "Unable to list target ‘"+targetURL+"’.") } } diff --git a/mb-main.go b/mb-main.go index d80b0a1d..7b121c2c 100644 --- a/mb-main.go +++ b/mb-main.go @@ -93,8 +93,7 @@ func mainMakeBucket(ctx *cli.Context) { config := mustGetMcConfig() for _, arg := range ctx.Args() { - targetURL, err := getCanonicalizedURL(arg, config.Aliases) - fatalIf(err.Trace(arg), "Unable to parse bucket ‘"+arg+"’.") + targetURL := aliasExpand(arg, config.Aliases) fatalIf(doMakeBucketCmd(targetURL).Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.") console.Println(MakeBucketMessage{ diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 2f44107b..4b6f7cf7 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -17,6 +17,8 @@ package s3 import ( + "errors" + "fmt" "io" "net/http" "os" @@ -133,6 +135,10 @@ func (c *s3Client) MakeBucket() *probe.Error { if object != "" { return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()}) } + if bucket == "" { + return probe.NewError(errors.New(fmt.Sprintf("Bucket name is empty."))) + } + err := c.api.MakeBucket(bucket, minio.BucketACL("private")) if err != nil { return probe.NewError(err) diff --git a/share-main.go b/share-main.go index c7d65b7a..fb5970cb 100644 --- a/share-main.go +++ b/share-main.go @@ -92,11 +92,10 @@ func mainShare(ctx *cli.Context) { fatalIf(probe.NewError(err), "Unable to parse time argument.") } - targetURL, err := getCanonicalizedURL(url, config.Aliases) - fatalIf(err.Trace(url), "Unable to parse argument ‘"+url+"’.") + targetURL := aliasExpand(url, config.Aliases) // if recursive strip off the "..." - err = doShareCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL), shareDuration{duration: expires}) + err := doShareCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL), shareDuration{duration: expires}) fatalIf(err.Trace(targetURL), "Unable to generate URL for sharing.") } diff --git a/typed-errors.go b/typed-errors.go index c77ea769..a5e51801 100644 --- a/typed-errors.go +++ b/typed-errors.go @@ -39,10 +39,6 @@ var ( return probe.NewError(errors.New("Error reading glob URL ‘" + glob + "’ while comparing with ‘" + request + "’.")).Untrace() } - errInvalidURL = func(URL string) *probe.Error { - return probe.NewError(errors.New("Invalid URL ‘" + URL + "’.")).Untrace() - } - errNoMatchingHost = func(URL string) *probe.Error { return probe.NewError(errors.New("No matching host found for the given URL ‘" + URL + "’.")).Untrace() } diff --git a/url.go b/url.go index e8d7a658..ef761c76 100644 --- a/url.go +++ b/url.go @@ -29,12 +29,6 @@ const ( recursiveSeparator = "..." ) -// url2Stat - Returns client, config and its stat Content from the URL. -func isValidURL(url string) bool { - // TODO: Requires a better logic. - return true -} - // urlJoinPath Join a path to existing URL. func urlJoinPath(url1, url2 string) string { u1 := client.NewURL(url1) @@ -60,29 +54,6 @@ func stripRecursiveURL(urlStr string) string { return urlStr } -// getCanonicalizedURL - extracts URL string from a single cmd-line argument. -func getCanonicalizedURL(arg string, aliases map[string]string) (string, *probe.Error) { - // Check and expand Alias - urlStr := aliasExpand(arg, aliases) - if !isValidURL(urlStr) { - // Not a valid URL. Return error - return "", errInvalidURL(urlStr).Trace() - } - return urlStr, nil -} - -// getCanonicalizedURLs - extracts multiple URL strings from a single cmd-line argument. -func getCanonicalizedURLs(args []string, aliases map[string]string) (urls []string, err *probe.Error) { - for _, arg := range args { - u, err := getCanonicalizedURL(arg, aliases) - if err != nil { - return nil, err.Trace(arg) - } - urls = append(urls, u) - } - return urls, nil -} - // args2URLs extracts source and target URLs from command-line args. func args2URLs(args []string) ([]string, *probe.Error) { config, err := getMcConfig() @@ -91,9 +62,9 @@ func args2URLs(args []string) ([]string, *probe.Error) { } // Convert arguments to URLs: expand alias, fix format... - URLs, err := getCanonicalizedURLs(args, config.Aliases) - if err != nil { - return nil, err.Trace(args...) + URLs := []string{} + for _, arg := range args { + URLs = append(URLs, aliasExpand(arg, config.Aliases)) } return URLs, nil }