Fixed ./mc sync <dir> bug exposed after previous changes

This commit is contained in:
Harshavardhana
2015-03-04 02:29:07 -08:00
parent 1bf6bd8b5b
commit 97f3016fee
2 changed files with 24 additions and 13 deletions
+18 -9
View File
@@ -83,24 +83,33 @@ func (c *Client) transport() http.RoundTripper {
// bucketURL returns the URL prefix of the bucket, with trailing slash
func (c *Client) bucketURL(bucket string) string {
if !c.S3ForcePathStyle {
if IsValidBucket(bucket) && !strings.Contains(bucket, ".") {
var url_ string
// if localhost forcePathStyle
if strings.Contains(c.endpoint(), "localhost") || strings.Contains(bucket, "127.0.0.1") {
url_ = fmt.Sprintf("%s/%s", c.endpoint(), bucket)
} else if strings.Contains(c.endpoint(), "amazonaws.com") {
var url_ string
if IsValidBucket(bucket) && !strings.Contains(bucket, ".") {
// if localhost forcePathStyle
if strings.Contains(c.endpoint(), "localhost") || strings.Contains(bucket, "127.0.0.1") {
url_ = fmt.Sprintf("%s/%s", c.endpoint(), bucket)
goto ret
}
if !c.S3ForcePathStyle {
if strings.Contains(c.endpoint(), "amazonaws.com") {
url_ = fmt.Sprintf("https://%s.%s/", bucket, strings.TrimPrefix(c.endpoint(), "https://"))
} else {
url_ = fmt.Sprintf("http://%s.%s/", bucket, strings.TrimPrefix(c.endpoint(), "http://"))
}
return url_
} else {
url_ = fmt.Sprintf("%s/%s", c.endpoint(), bucket)
}
}
return fmt.Sprintf("%s/%s", c.endpoint(), bucket)
ret:
return url_
}
func (c *Client) keyURL(bucket, key string) string {
// if localhost forcePathStyle
if strings.Contains(c.endpoint(), "localhost") || strings.Contains(bucket, "127.0.0.1") || c.S3ForcePathStyle {
return c.bucketURL(bucket) + "/" + key
}
return c.bucketURL(bucket) + key
}
+6 -4
View File
@@ -51,7 +51,7 @@ func isValidBucketName(p string) {
}
}
func printWalk(p string, info os.FileInfo, err error) error {
func putWalk(p string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
@@ -68,11 +68,11 @@ func printWalk(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
log.Printf("%s uploaded -- to bucket:%s", key, bucketname)
return nil
}
func doFsSync(c *cli.Context) {
switch len(c.Args()) {
case 1:
input := path.Clean(c.Args().Get(0))
@@ -90,8 +90,10 @@ func doFsSync(c *cli.Context) {
if err != nil {
log.Fatal(err)
}
filepath.Walk(input, printWalk)
err = filepath.Walk(input, putWalk)
if err != nil {
log.Fatal(err)
}
default:
log.Fatal("Requires a directory name <Directory>")
}