From 9a40a67410eb77fea2d949fd0004e014f391bd9e Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 25 Jan 2016 00:48:54 -0800 Subject: [PATCH] mc: Vendorize to new changes. - Fix 0byte file uploads to be not uploaded as multipart. - Fix bucket requests to have a '/' at the end for path style - fixes #1579 - Handle progress bar, if pb.Total is '0'. --- pkg/client/s3/s3_test.go | 6 +-- .../minio/minio-go/api-put-bucket.go | 2 +- .../minio/minio-go/api-put-object-file.go | 2 +- .../minio/minio-go/api-put-object-progress.go | 2 +- vendor/github.com/minio/minio-go/api.go | 9 ++-- .../minio/minio-go/api_functional_v2_test.go | 51 +++++++++++++++++++ .../github.com/minio/minio-go/bucket-cache.go | 2 +- .../minio/minio-go/request-signature-v2.go | 4 +- vendor/github.com/minio/pb/pb.go | 26 +++++++--- vendor/vendor.json | 8 +-- 10 files changed, 87 insertions(+), 25 deletions(-) diff --git a/pkg/client/s3/s3_test.go b/pkg/client/s3/s3_test.go index ae356bd5..978c6435 100644 --- a/pkg/client/s3/s3_test.go +++ b/pkg/client/s3/s3_test.go @@ -51,7 +51,7 @@ func (h bucketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { response := []byte("bucket2015-05-20T23:05:09.230Zminiominio") w.Header().Set("Content-Length", strconv.Itoa(len(response))) w.Write(response) - case r.URL.Path == "/bucket": + case r.URL.Path == "/bucket/": // Handler for incoming ListObjects request. response := []byte("259d04a13802ae09c7e41be50ccc6baaobject2015-05-21T18:24:21.097Z22061miniominioSTANDARDfalse1000testbucket") w.Header().Set("Content-Length", strconv.Itoa(len(response))) @@ -150,7 +150,7 @@ func (h objectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Handler for list multipart upload request. if _, ok := r.URL.Query()["uploads"]; ok { - if r.URL.Path == "/bucket" { + if r.URL.Path == "/bucket/" { response := []byte("bucket1000false") w.Header().Set("Content-Length", strconv.Itoa(len(response))) w.Write(response) @@ -178,7 +178,7 @@ var _ = Suite(&MySuite{}) // Test bucket operations. func (s *MySuite) TestBucketOperations(c *C) { bucket := bucketHandler(bucketHandler{ - resource: "/bucket", + resource: "/bucket/", }) server := httptest.NewServer(bucket) defer server.Close() diff --git a/vendor/github.com/minio/minio-go/api-put-bucket.go b/vendor/github.com/minio/minio-go/api-put-bucket.go index f9431136..e68ab824 100644 --- a/vendor/github.com/minio/minio-go/api-put-bucket.go +++ b/vendor/github.com/minio/minio-go/api-put-bucket.go @@ -101,7 +101,7 @@ func (c Client) makeBucketRequest(bucketName string, acl BucketACL, location str targetURL.Path = "/" } else { // If not fall back to using path style. - targetURL.Path = "/" + bucketName + targetURL.Path = "/" + bucketName + "/" } } diff --git a/vendor/github.com/minio/minio-go/api-put-object-file.go b/vendor/github.com/minio/minio-go/api-put-object-file.go index b7fa86fd..d212dfb8 100644 --- a/vendor/github.com/minio/minio-go/api-put-object-file.go +++ b/vendor/github.com/minio/minio-go/api-put-object-file.go @@ -88,7 +88,7 @@ func (c Client) FPutObject(bucketName, objectName, filePath, contentType string) } // Small object upload is initiated for uploads for input data size smaller than 5MiB. - if fileSize < minPartSize { + if fileSize < minPartSize && fileSize >= 0 { return c.putObjectSingle(bucketName, objectName, fileReader, fileSize, contentType, nil) } // Upload all large objects as multipart. diff --git a/vendor/github.com/minio/minio-go/api-put-object-progress.go b/vendor/github.com/minio/minio-go/api-put-object-progress.go index de3b348f..ae4425d4 100644 --- a/vendor/github.com/minio/minio-go/api-put-object-progress.go +++ b/vendor/github.com/minio/minio-go/api-put-object-progress.go @@ -82,7 +82,7 @@ func (c Client) PutObjectWithProgress(bucketName, objectName string, reader io.R } // putSmall object. - if size < minPartSize && size > 0 { + if size < minPartSize && size >= 0 { return c.putObjectSingle(bucketName, objectName, reader, size, contentType, progress) } // For all sizes greater than 5MiB do multipart. diff --git a/vendor/github.com/minio/minio-go/api.go b/vendor/github.com/minio/minio-go/api.go index b3993460..96cab8c0 100644 --- a/vendor/github.com/minio/minio-go/api.go +++ b/vendor/github.com/minio/minio-go/api.go @@ -181,7 +181,7 @@ func (c *Client) SetCustomTransport(customHTTPTransport http.RoundTripper) { } // TraceOn - enable HTTP tracing. -func (c *Client) TraceOn(outputStream io.Writer) error { +func (c *Client) TraceOn(outputStream io.Writer) { // if outputStream is nil then default to os.Stdout. if outputStream == nil { outputStream = os.Stdout @@ -191,7 +191,6 @@ func (c *Client) TraceOn(outputStream io.Writer) error { // Enable tracing. c.isTraceEnabled = true - return nil } // TraceOff - disable HTTP tracing. @@ -471,9 +470,9 @@ func (c Client) makeTargetURL(bucketName, objectName, bucketLocation string, que } } else { // If not fall back to using path style. - urlStr = urlStr + bucketName + urlStr = urlStr + bucketName + "/" if objectName != "" { - urlStr = urlStr + "/" + urlEncodePath(objectName) + urlStr = urlStr + urlEncodePath(objectName) } } } @@ -528,6 +527,6 @@ type CloudStorageClient interface { SetCustomTransport(customTransport http.RoundTripper) // HTTP tracing methods. - TraceOn(traceOutput io.Writer) error + TraceOn(traceOutput io.Writer) TraceOff() } diff --git a/vendor/github.com/minio/minio-go/api_functional_v2_test.go b/vendor/github.com/minio/minio-go/api_functional_v2_test.go index 1c7da682..ba0d3bcd 100644 --- a/vendor/github.com/minio/minio-go/api_functional_v2_test.go +++ b/vendor/github.com/minio/minio-go/api_functional_v2_test.go @@ -370,6 +370,57 @@ func TestResumableFPutObjectV2(t *testing.T) { } } +// Tests various bucket supported formats. +func TestMakeBucketRegionsV2(t *testing.T) { + if testing.Short() { + t.Skip("skipping functional tests for short runs") + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Connect and make sure bucket exists. + c, err := minio.New( + "s3.amazonaws.com", + os.Getenv("ACCESS_KEY"), + os.Getenv("SECRET_KEY"), + false, + ) + if err != nil { + t.Fatal("Error:", err) + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano())) + + // Make a new bucket in 'eu-central-1'. + if err = c.MakeBucket(bucketName, "private", "eu-central-1"); err != nil { + t.Fatal("Error:", err, bucketName) + } + + if err = c.RemoveBucket(bucketName); err != nil { + t.Fatal("Error:", err, bucketName) + } + + // Make a new bucket with '.' in its name, in 'us-west-2'. This + // request is internally staged into a path style instead of + // virtual host style. + if err = c.MakeBucket(bucketName+".withperiod", "private", "us-west-2"); err != nil { + t.Fatal("Error:", err, bucketName+".withperiod") + } + + // Remove the newly created bucket. + if err = c.RemoveBucket(bucketName + ".withperiod"); err != nil { + t.Fatal("Error:", err, bucketName+".withperiod") + } +} + // Tests resumable put object multipart upload. func TestResumablePutObjectV2(t *testing.T) { if testing.Short() { diff --git a/vendor/github.com/minio/minio-go/bucket-cache.go b/vendor/github.com/minio/minio-go/bucket-cache.go index 4af161c1..c0b4f0cb 100644 --- a/vendor/github.com/minio/minio-go/bucket-cache.go +++ b/vendor/github.com/minio/minio-go/bucket-cache.go @@ -127,7 +127,7 @@ func (c Client) getBucketLocationRequest(bucketName string) (*http.Request, erro // Set get bucket location always as path style. targetURL := c.endpointURL - targetURL.Path = filepath.Join(bucketName, "") + targetURL.Path = filepath.Join(bucketName, "") + "/" targetURL.RawQuery = urlValues.Encode() // Get a new HTTP request for the method. diff --git a/vendor/github.com/minio/minio-go/request-signature-v2.go b/vendor/github.com/minio/minio-go/request-signature-v2.go index 69682818..9458c4fd 100644 --- a/vendor/github.com/minio/minio-go/request-signature-v2.go +++ b/vendor/github.com/minio/minio-go/request-signature-v2.go @@ -251,10 +251,9 @@ var resourceList = []string{ // CanonicalizedResource = [ "/" + Bucket ] + // + // [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"]; -func writeCanonicalizedResource(buf *bytes.Buffer, req http.Request) error { +func writeCanonicalizedResource(buf *bytes.Buffer, req http.Request) { // Save request URL. requestURL := req.URL - // Get encoded URL path. path := encodeURL2Path(requestURL) buf.WriteString(path) @@ -285,5 +284,4 @@ func writeCanonicalizedResource(buf *bytes.Buffer, req http.Request) error { } } } - return nil } diff --git a/vendor/github.com/minio/pb/pb.go b/vendor/github.com/minio/pb/pb.go index 92523264..0d5542d5 100644 --- a/vendor/github.com/minio/pb/pb.go +++ b/vendor/github.com/minio/pb/pb.go @@ -243,7 +243,12 @@ func (pb *ProgressBar) write(current int64) { // percents if pb.ShowPercent { - percent := float64(current) / (float64(pb.Total) / float64(100)) + var percent float64 + if pb.Total > 0 { + percent = float64(current) / (float64(pb.Total) / float64(100)) + } else { + percent = float64(current) / float64(100) + } percentBox = fmt.Sprintf(" %.02f %% ", percent) } @@ -262,14 +267,25 @@ func (pb *ProgressBar) write(current int64) { select { case <-pb.finish: if pb.ShowFinalTime { - left := (fromStart / time.Second) * time.Second + var left time.Duration + if pb.Total > 0 { + left = (fromStart / time.Second) * time.Second + } else { + left = (time.Duration(currentFromStart) / time.Second) * time.Second + } timeLeftBox = left.String() } default: if pb.ShowTimeLeft && currentFromStart > 0 { perEntry := fromStart / time.Duration(currentFromStart) - left := time.Duration(pb.Total-currentFromStart) * perEntry - left = (left / time.Second) * time.Second + var left time.Duration + if pb.Total > 0 { + left = time.Duration(pb.Total-currentFromStart) * perEntry + left = (left / time.Second) * time.Second + } else { + left = time.Duration(currentFromStart) * perEntry + left = (left / time.Second) * time.Second + } timeLeftBox = left.String() } } @@ -301,10 +317,8 @@ func (pb *ProgressBar) write(current int64) { } else if curCount > 0 { barBox += strings.Repeat(pb.Current, curCount-1) + pb.CurrentN } - barBox += strings.Repeat(pb.Empty, emptCount) + pb.BarEnd } else { - barBox = pb.BarStart pos := size - int(current)%int(size) if pos-1 > 0 { diff --git a/vendor/vendor.json b/vendor/vendor.json index 99cd2328..e02bd285 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -29,8 +29,8 @@ }, { "path": "github.com/minio/minio-go", - "revision": "412df729f2c19ce60895770403f266cf5eac56f7", - "revisionTime": "2016-01-22T16:23:42-08:00" + "revision": "65e5154d5edc3c1c1279d71ab595cc4a6bb94b1a", + "revisionTime": "2016-01-25T00:19:13-08:00" }, { "path": "github.com/minio/minio-xl/pkg/atomic", @@ -59,8 +59,8 @@ }, { "path": "github.com/minio/pb", - "revision": "f078cde702e9e2548c47ec71b889381954dd4063", - "revisionTime": "2016-01-12T19:37:35-08:00" + "revision": "ebf84553b05b6afbd47274497a1d7b7861100398", + "revisionTime": "2016-01-25T00:47:32-08:00" }, { "path": "github.com/olekukonko/ts",