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:
+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 {
|
||||
|
||||
Reference in New Issue
Block a user