Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changes for mc global context fix #1302

Merged
merged 1 commit into from Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions api-compose-object.go
Expand Up @@ -408,16 +408,20 @@ func (c Client) uploadPartCopy(ctx context.Context, bucket, object, uploadID str
return p, nil
}

// ComposeObjectWithProgress - creates an object using server-side copying of
// ComposeObjectWithProgress is a wrapper for ComposeObjectWithProgressWithContext.
func (c Client) ComposeObjectWithProgress(dst DestinationInfo, srcs []SourceInfo, progress io.Reader) error {
return c.ComposeObjectWithProgressWithContext(context.Background(), dst, srcs, progress)
}

// ComposeObjectWithProgressWithContext - creates an object using server-side copying of
// existing objects. It takes a list of source objects (with optional
// offsets) and concatenates them into a new object using only
// server-side copying operations. Optionally takes progress reader hook
// for applications to look at current progress.
func (c Client) ComposeObjectWithProgress(dst DestinationInfo, srcs []SourceInfo, progress io.Reader) error {
func (c Client) ComposeObjectWithProgressWithContext(ctx context.Context, dst DestinationInfo, srcs []SourceInfo, progress io.Reader) error {
if len(srcs) < 1 || len(srcs) > maxPartsCount {
return ErrInvalidArgument("There must be as least one and up to 10000 source objects.")
}
ctx := context.Background()
srcSizes := make([]int64, len(srcs))
var totalSize, size, totalParts int64
var srcUserMeta map[string]string
Expand Down Expand Up @@ -478,7 +482,7 @@ func (c Client) ComposeObjectWithProgress(dst DestinationInfo, srcs []SourceInfo
// involved, it is being copied wholly and at most 5GiB in
// size, emptyfiles are also supported).
if (totalParts == 1 && srcs[0].start == -1 && totalSize <= maxPartSize) || (totalSize == 0) {
return c.CopyObjectWithProgress(dst, srcs[0], progress)
return c.CopyObjectWithProgressWithContext(ctx, dst, srcs[0], progress)
}

// Now, handle multipart-copy cases.
Expand Down
13 changes: 9 additions & 4 deletions api-get-lifecycle.go
Expand Up @@ -26,13 +26,18 @@ import (
"github.com/minio/minio-go/v6/pkg/s3utils"
)

// GetBucketLifecycle - get bucket lifecycle.
// GetBucketLifecycle is a wrapper for GetBucketLifecycleWithContext.
func (c Client) GetBucketLifecycle(bucketName string) (string, error) {
return c.GetBucketLifecycleWithContext(context.Background(), bucketName)
}

// GetBucketLifecycleWithContext - get bucket lifecycle.
func (c Client) GetBucketLifecycleWithContext(ctx context.Context, bucketName string) (string, error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return "", err
}
bucketLifecycle, err := c.getBucketLifecycle(bucketName)
bucketLifecycle, err := c.getBucketLifecycle(ctx, bucketName)
if err != nil {
errResponse := ToErrorResponse(err)
if errResponse.Code == "NoSuchLifecycleConfiguration" {
Expand All @@ -44,14 +49,14 @@ func (c Client) GetBucketLifecycle(bucketName string) (string, error) {
}

// Request server for current bucket lifecycle.
func (c Client) getBucketLifecycle(bucketName string) (string, error) {
func (c Client) getBucketLifecycle(ctx context.Context, bucketName string) (string, error) {
// Get resources properly escaped and lined up before
// using them in http request.
urlValues := make(url.Values)
urlValues.Set("lifecycle", "")

// Execute GET on bucket to get lifecycle.
resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{
resp, err := c.executeMethod(ctx, "GET", requestMetadata{
bucketName: bucketName,
queryValues: urlValues,
})
Expand Down
13 changes: 9 additions & 4 deletions api-get-policy.go
Expand Up @@ -26,13 +26,18 @@ import (
"github.com/minio/minio-go/v6/pkg/s3utils"
)

// GetBucketPolicy - get bucket policy at a given path.
// GetBucketPolicy is a wrapper for GetBucketPolicyWithContext
func (c Client) GetBucketPolicy(bucketName string) (string, error) {
return c.GetBucketPolicyWithContext(context.Background(), bucketName)
}

// GetBucketPolicyWithContext - get bucket policy at a given path.
func (c Client) GetBucketPolicyWithContext(ctx context.Context, bucketName string) (string, error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return "", err
}
bucketPolicy, err := c.getBucketPolicy(bucketName)
bucketPolicy, err := c.getBucketPolicy(ctx, bucketName)
if err != nil {
errResponse := ToErrorResponse(err)
if errResponse.Code == "NoSuchBucketPolicy" {
Expand All @@ -44,14 +49,14 @@ func (c Client) GetBucketPolicy(bucketName string) (string, error) {
}

// Request server for current bucket policy.
func (c Client) getBucketPolicy(bucketName string) (string, error) {
func (c Client) getBucketPolicy(ctx context.Context, bucketName string) (string, error) {
// Get resources properly escaped and lined up before
// using them in http request.
urlValues := make(url.Values)
urlValues.Set("policy", "")

// Execute GET on bucket to list objects.
resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{
resp, err := c.executeMethod(ctx, "GET", requestMetadata{
bucketName: bucketName,
queryValues: urlValues,
contentSHA256Hex: emptySHA256Hex,
Expand Down