URL related bug fixes and cleanup

This commit is contained in:
Anand Babu (AB) Periasamy
2015-08-30 02:14:24 -07:00
parent 908b58f4c5
commit fddcb821fa
12 changed files with 34 additions and 76 deletions
+1 -2
View File
@@ -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+"’.")
+1 -1
View File
@@ -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.
+1 -4
View File
@@ -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 {
-3
View File
@@ -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)
+2 -5
View File
@@ -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)) {
+15 -17
View File
@@ -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()
+2 -3
View File
@@ -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+"’.")
}
}
+1 -2
View File
@@ -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{
+6
View File
@@ -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)
+2 -3
View File
@@ -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.")
}
-4
View File
@@ -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()
}
+3 -32
View File
@@ -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
}