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'.
This commit is contained in:
@@ -51,7 +51,7 @@ func (h bucketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
response := []byte("<ListAllMyBucketsResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Buckets><Bucket><Name>bucket</Name><CreationDate>2015-05-20T23:05:09.230Z</CreationDate></Bucket></Buckets><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner></ListAllMyBucketsResult>")
|
||||
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("<ListBucketResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Contents><ETag>259d04a13802ae09c7e41be50ccc6baa</ETag><Key>object</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Delimiter></Delimiter><EncodingType></EncodingType><IsTruncated>false</IsTruncated><Marker></Marker><MaxKeys>1000</MaxKeys><Name>testbucket</Name><NextMarker></NextMarker><Prefix></Prefix></ListBucketResult>")
|
||||
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("<ListMultipartUploadsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Bucket>bucket</Bucket><KeyMarker/><UploadIdMarker/><NextKeyMarker/><NextUploadIdMarker/><EncodingType/><MaxUploads>1000</MaxUploads><IsTruncated>false</IsTruncated><Prefix/><Delimiter/></ListMultipartUploadsResult>")
|
||||
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()
|
||||
|
||||
+1
-1
@@ -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 + "/"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+4
-5
@@ -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()
|
||||
}
|
||||
|
||||
+51
@@ -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() {
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+1
-3
@@ -251,10 +251,9 @@ var resourceList = []string{
|
||||
// CanonicalizedResource = [ "/" + Bucket ] +
|
||||
// <HTTP-Request-URI, from the protocol name up to the query string> +
|
||||
// [ 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
|
||||
}
|
||||
|
||||
+20
-6
@@ -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 {
|
||||
|
||||
Vendored
+4
-4
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user