From 97f3016fee0223bb85ea521d0abb4870f440bb0a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 4 Mar 2015 02:29:07 -0800 Subject: [PATCH] Fixed ./mc sync bug exposed after previous changes --- pkg/s3/client.go | 27 ++++++++++++++++++--------- s3-fs-sync.go | 10 ++++++---- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/pkg/s3/client.go b/pkg/s3/client.go index 7bc7e1be..6913d4b7 100644 --- a/pkg/s3/client.go +++ b/pkg/s3/client.go @@ -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 } diff --git a/s3-fs-sync.go b/s3-fs-sync.go index ad1af065..6339363b 100644 --- a/s3-fs-sync.go +++ b/s3-fs-sync.go @@ -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 ") }