diff --git a/cmd/client-fs.go b/cmd/client-fs.go index f22e788a..7a8b2e93 100644 --- a/cmd/client-fs.go +++ b/cmd/client-fs.go @@ -408,7 +408,7 @@ func (f *fsClient) put(reader io.Reader, size int64, metadata map[string][]strin } // Put - create a new file with metadata. -func (f *fsClient) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide) (int64, *probe.Error) { +func (f *fsClient) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, disableMultipart bool) (int64, *probe.Error) { if metadata["mc-attrs"] != "" { meta := make(map[string][]string) meta["mc-attrs"] = append(meta["mc-attrs"], metadata["mc-attrs"]) diff --git a/cmd/client-fs_test.go b/cmd/client-fs_test.go index bcda786e..575d34fd 100644 --- a/cmd/client-fs_test.go +++ b/cmd/client-fs_test.go @@ -45,7 +45,7 @@ func (s *TestSuite) TestList(c *C) { var n int64 n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) @@ -56,7 +56,7 @@ func (s *TestSuite) TestList(c *C) { reader = bytes.NewReader([]byte(data)) n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) @@ -84,7 +84,7 @@ func (s *TestSuite) TestList(c *C) { reader = bytes.NewReader([]byte(data)) n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) @@ -144,7 +144,7 @@ func (s *TestSuite) TestList(c *C) { reader = bytes.NewReader([]byte(data)) n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) @@ -251,7 +251,7 @@ func (s *TestSuite) TestPut(c *C) { var n int64 n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) } @@ -271,7 +271,7 @@ func (s *TestSuite) TestGet(c *C) { reader = bytes.NewReader([]byte(data)) n, err := fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) @@ -299,7 +299,7 @@ func (s *TestSuite) TestGetRange(c *C) { reader = bytes.NewReader([]byte(data)) n, err := fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) @@ -330,7 +330,7 @@ func (s *TestSuite) TestStatObject(c *C) { reader := bytes.NewReader([]byte(data)) n, err := fsClient.Put(context.Background(), reader, int64(dataLen), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) @@ -356,7 +356,7 @@ func (s *TestSuite) TestCopy(c *C) { reader = bytes.NewReader([]byte(data)) n, err := fsClientSource.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(data))) diff --git a/cmd/client-s3.go b/cmd/client-s3.go index 7d0e0924..a71a0c54 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -817,7 +817,7 @@ func (c *s3Client) Copy(source string, size int64, progress io.Reader, srcSSE, t } // Put - upload an object with custom metadata. -func (c *s3Client) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide) (int64, *probe.Error) { +func (c *s3Client) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, disableMultipart bool) (int64, *probe.Error) { bucket, object := c.url2BucketAndObject() if bucket == "" { return 0, probe.NewError(BucketNameEmpty{}) @@ -882,6 +882,7 @@ func (c *s3Client) Put(ctx context.Context, reader io.Reader, size int64, metada ContentLanguage: contentLanguage, StorageClass: strings.ToUpper(storageClass), ServerSideEncryption: sse, + DisableMultipart: disableMultipart, } if retainUntilDate != timeSentinel { opts.RetainUntilDate = &retainUntilDate diff --git a/cmd/client-s3_test.go b/cmd/client-s3_test.go index 78b319cc..bc984950 100644 --- a/cmd/client-s3_test.go +++ b/cmd/client-s3_test.go @@ -223,7 +223,7 @@ func (s *TestSuite) TestObjectOperations(c *C) { reader = bytes.NewReader(object.data) n, err := s3c.Put(context.Background(), reader, int64(len(object.data)), map[string]string{ "Content-Type": "application/octet-stream", - }, nil, nil) + }, nil, nil, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(object.data))) diff --git a/cmd/client.go b/cmd/client.go index ff558dd4..cb808014 100644 --- a/cmd/client.go +++ b/cmd/client.go @@ -67,7 +67,7 @@ type Client interface { // I/O operations with metadata. Get(sse encrypt.ServerSide) (reader io.ReadCloser, err *probe.Error) - Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide) (n int64, err *probe.Error) + Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, disableMultipart bool) (n int64, err *probe.Error) // Object Locking related API PutObjectRetention(mode *minio.RetentionMode, retainUntilDate *time.Time, bypassGovernance bool) *probe.Error PutObjectLegalHold(hold *minio.LegalHoldStatus) *probe.Error diff --git a/cmd/common-methods.go b/cmd/common-methods.go index e776d58c..650524a5 100644 --- a/cmd/common-methods.go +++ b/cmd/common-methods.go @@ -241,12 +241,12 @@ func putTargetRetention(ctx context.Context, alias string, urlStr string, metada } // putTargetStream writes to URL from Reader. -func putTargetStream(ctx context.Context, alias string, urlStr string, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide) (int64, *probe.Error) { +func putTargetStream(ctx context.Context, alias string, urlStr string, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, disableMultipart bool) (int64, *probe.Error) { targetClnt, err := newClientFromAlias(alias, urlStr) if err != nil { return 0, err.Trace(alias, urlStr) } - n, err := targetClnt.Put(ctx, reader, size, metadata, progress, sse) + n, err := targetClnt.Put(ctx, reader, size, metadata, progress, sse, disableMultipart) if err != nil { return n, err.Trace(alias, urlStr) } @@ -254,7 +254,7 @@ func putTargetStream(ctx context.Context, alias string, urlStr string, reader io } // putTargetStreamWithURL writes to URL from reader. If length=-1, read until EOF. -func putTargetStreamWithURL(urlStr string, reader io.Reader, size int64, sse encrypt.ServerSide) (int64, *probe.Error) { +func putTargetStreamWithURL(urlStr string, reader io.Reader, size int64, sse encrypt.ServerSide, disableMultipart bool) (int64, *probe.Error) { alias, urlStrFull, _, err := expandAlias(urlStr) if err != nil { return 0, err.Trace(alias, urlStr) @@ -263,7 +263,7 @@ func putTargetStreamWithURL(urlStr string, reader io.Reader, size int64, sse enc metadata := map[string]string{ "Content-Type": contentType, } - return putTargetStream(context.Background(), alias, urlStrFull, reader, size, metadata, nil, sse) + return putTargetStream(context.Background(), alias, urlStrFull, reader, size, metadata, nil, sse, disableMultipart) } // copySourceToTargetURL copies to targetURL from source. @@ -387,7 +387,7 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader, metadata[k] = v } _, err = putTargetStream(ctx, targetAlias, targetURL.String(), reader, length, filterMetadata(metadata), - progress, tgtSSE) + progress, tgtSSE, urls.DisableMultipart) } if err != nil { return urls.WithError(err.Trace(sourceURL.String())) diff --git a/cmd/cp-main.go b/cmd/cp-main.go index e2c257d9..db951760 100644 --- a/cmd/cp-main.go +++ b/cmd/cp-main.go @@ -69,6 +69,10 @@ var ( Name: "preserve, a", Usage: "preserve filesystem attributes (mode, ownership, timestamps)", }, + cli.BoolFlag{ + Name: "disable-multipart", + Usage: "disable multipart upload feature", + }, } ) @@ -144,6 +148,9 @@ EXAMPLES: 16. Copy a text file to an object storage with object lock mode set to 'GOVERNANCE' with retention date. {{.Prompt}} {{.HelpName}} --attr "x-amz-object-lock-mode=GOVERNANCE;x-amz-object-lock-retain-until-date=2020-01-11T01:57:02Z" locked.txt play/locked-bucket/ + + 17. Copy a text file to an object storage and disable multipart upload feature. + {{.Prompt}} {{.HelpName}} --disable-multipart myobject.txt play/mybucket `, } @@ -447,6 +454,9 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p cpURLs.TargetContent.Metadata["mc-attrs"] = attrValue } } + + cpURLs.DisableMultipart = cli.Bool("disable-multipart") + // Verify if previously copied, notify progress bar. if isCopied != nil && isCopied(cpURLs.SourceContent.URL.String()) { queueCh <- func() URLs { @@ -595,6 +605,7 @@ func mainCopy(ctx *cli.Context) error { session.Header.CommandBoolFlags["preserve"] = ctx.Bool("preserve") } session.Header.UserMetaData = userMetaMap + session.Header.CommandBoolFlags["disable-multipart"] = ctx.Bool("disable-multipart") var e error if session.Header.RootPath, e = os.Getwd(); e != nil { diff --git a/cmd/pipe-main.go b/cmd/pipe-main.go index 298be715..ae7df770 100644 --- a/cmd/pipe-main.go +++ b/cmd/pipe-main.go @@ -79,7 +79,7 @@ func pipe(targetURL string, encKeyDB map[string][]prefixSSEPair) *probe.Error { // Stream from stdin to multiple objects until EOF. // Ignore size, since os.Stat() would not return proper size all the time // for local filesystem for example /proc files. - _, err := putTargetStreamWithURL(targetURL, os.Stdin, -1, sseKey) + _, err := putTargetStreamWithURL(targetURL, os.Stdin, -1, sseKey, false) // TODO: See if this check is necessary. switch e := err.ToGoError().(type) { case *os.PathError: diff --git a/cmd/urls.go b/cmd/urls.go index d5596797..d39a8f34 100644 --- a/cmd/urls.go +++ b/cmd/urls.go @@ -22,14 +22,15 @@ import ( // URLs contains source and target urls type URLs struct { - SourceAlias string - SourceContent *clientContent - TargetAlias string - TargetContent *clientContent - TotalCount int64 - TotalSize int64 - encKeyDB map[string][]prefixSSEPair - Error *probe.Error `json:"-"` + SourceAlias string + SourceContent *clientContent + TargetAlias string + TargetContent *clientContent + TotalCount int64 + TotalSize int64 + DisableMultipart bool + encKeyDB map[string][]prefixSSEPair + Error *probe.Error `json:"-"` } // WithError sets the error and returns object diff --git a/go.mod b/go.mod index b1f2b8e7..6c190e2f 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/mattn/go-runewidth v0.0.5 // indirect github.com/minio/cli v1.22.0 github.com/minio/minio v0.0.0-20200327214830-6f992134a25f - github.com/minio/minio-go/v6 v6.0.51-0.20200319192131-097caa7760c7 + github.com/minio/minio-go/v6 v6.0.51-0.20200401083717-eadbcae2a0e6 github.com/minio/sha256-simd v0.1.1 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/profile v1.3.0