diff --git a/cmd/client-fs.go b/cmd/client-fs.go index d7efd378..a46c88f8 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, disableMultipart bool) (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, md5, 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 f8ef0a10..325ce656 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, false) + }, nil, nil, false, 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, false) + }, nil, nil, false, 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, false) + }, nil, nil, false, 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, false) + }, nil, nil, false, 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, false) + }, nil, nil, false, 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, false) + }, nil, nil, false, 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, false) + }, nil, nil, false, 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, false) + }, nil, nil, false, 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, false) + }, nil, nil, false, 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 b4585470..6c686caa 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -885,7 +885,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, disableMultipart bool) (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, md5, disableMultipart bool) (int64, *probe.Error) { bucket, object := c.url2BucketAndObject() if bucket == "" { return 0, probe.NewError(BucketNameEmpty{}) @@ -950,23 +950,21 @@ func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, metada ContentLanguage: contentLanguage, StorageClass: strings.ToUpper(storageClass), ServerSideEncryption: sse, + SendContentMd5: md5, DisableMultipart: disableMultipart, } if !retainUntilDate.IsZero() && !retainUntilDate.Equal(timeSentinel) { opts.RetainUntilDate = &retainUntilDate - opts.SendContentMd5 = true } if lockModeStr != "" { opts.Mode = &lockMode - opts.SendContentMd5 = true } if lh, ok := metadata[AmzObjectLockLegalHold]; ok { delete(metadata, AmzObjectLockLegalHold) opts.LegalHold = minio.LegalHoldStatus(strings.ToUpper(lh)) - opts.SendContentMd5 = true } n, e := c.api.PutObjectWithContext(ctx, bucket, object, reader, size, opts) diff --git a/cmd/client-s3_test.go b/cmd/client-s3_test.go index 16be8c51..73044d6b 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, false) + }, nil, nil, false, false) c.Assert(err, IsNil) c.Assert(n, Equals, int64(len(object.data))) diff --git a/cmd/client.go b/cmd/client.go index c402615a..fc285181 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, disableMultipart bool) (n int64, err *probe.Error) + Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, 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 049f1812..40ccca66 100644 --- a/cmd/common-methods.go +++ b/cmd/common-methods.go @@ -297,7 +297,7 @@ func putTargetRetention(ctx context.Context, alias string, urlStr string, metada } // putTargetStream writes to URL from Reader. -func putTargetStream(ctx context.Context, alias, urlStr, mode, until, legalHold string, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, disableMultipart bool) (int64, *probe.Error) { +func putTargetStream(ctx context.Context, alias, urlStr, mode, until, legalHold string, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart bool) (int64, *probe.Error) { targetClnt, err := newClientFromAlias(alias, urlStr) if err != nil { return 0, err.Trace(alias, urlStr) @@ -312,7 +312,7 @@ func putTargetStream(ctx context.Context, alias, urlStr, mode, until, legalHold if legalHold != "" { metadata[AmzObjectLockLegalHold] = legalHold } - n, err := targetClnt.Put(ctx, reader, size, metadata, progress, sse, disableMultipart) + n, err := targetClnt.Put(ctx, reader, size, metadata, progress, sse, md5, disableMultipart) if err != nil { return n, err.Trace(alias, urlStr) } @@ -320,7 +320,7 @@ func putTargetStream(ctx context.Context, alias, urlStr, mode, until, legalHold } // putTargetStreamWithURL writes to URL from reader. If length=-1, read until EOF. -func putTargetStreamWithURL(urlStr string, reader io.Reader, size int64, sse encrypt.ServerSide, disableMultipart bool) (int64, *probe.Error) { +func putTargetStreamWithURL(urlStr string, reader io.Reader, size int64, sse encrypt.ServerSide, md5, disableMultipart bool) (int64, *probe.Error) { alias, urlStrFull, _, err := expandAlias(urlStr) if err != nil { return 0, err.Trace(alias, urlStr) @@ -329,7 +329,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, disableMultipart) + return putTargetStream(context.Background(), alias, urlStrFull, "", "", "", reader, size, metadata, nil, sse, md5, disableMultipart) } // copySourceToTargetURL copies to targetURL from source. @@ -482,11 +482,12 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader, if isReadAt(reader) { _, err = putTargetStream(ctx, targetAlias, targetURL.String(), mode, until, urls.TargetContent.LegalHold, reader, length, filterMetadata(metadata), - progress, tgtSSE, urls.DisableMultipart) + progress, tgtSSE, urls.MD5, urls.DisableMultipart) } else { _, err = putTargetStream(ctx, targetAlias, targetURL.String(), mode, until, urls.TargetContent.LegalHold, io.LimitReader(reader, length), - length, filterMetadata(metadata), progress, tgtSSE, urls.DisableMultipart) + length, filterMetadata(metadata), progress, tgtSSE, urls.MD5, + urls.DisableMultipart) } } if err != nil { diff --git a/cmd/cp-main.go b/cmd/cp-main.go index f09c6446..219709a9 100644 --- a/cmd/cp-main.go +++ b/cmd/cp-main.go @@ -73,6 +73,10 @@ var ( Name: "disable-multipart", Usage: "disable multipart upload feature", }, + cli.BoolFlag{ + Name: "md5", + Usage: "force all upload(s) to calculate md5sum checksum", + }, cli.StringFlag{ Name: rmFlag, Usage: "retention mode to be applied on the object (governance, compliance)", @@ -490,6 +494,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p } preserve := cli.Bool("preserve") + cpURLs.MD5 = cli.Bool("md5") cpURLs.DisableMultipart = cli.Bool("disable-multipart") // Verify if previously copied, notify progress bar. @@ -646,6 +651,7 @@ func mainCopy(ctx *cli.Context) error { session.Header.CommandBoolFlags["preserve"] = ctx.Bool("preserve") } session.Header.UserMetaData = userMetaMap + session.Header.CommandBoolFlags["md5"] = ctx.Bool("md5") session.Header.CommandBoolFlags["disable-multipart"] = ctx.Bool("disable-multipart") var e error diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index 5a3563d5..dae49ace 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -68,9 +68,17 @@ var ( Usage: "preserve file(s)/object(s) attributes and bucket policy rules on target bucket(s)", }, cli.BoolFlag{ + Name: "md5", + Usage: "force all upload(s) to calculate md5sum checksum", + }, + cli.StringFlag{ Name: "multi-master", Usage: "enable multi-master multi-site setup", }, + cli.BoolFlag{ + Name: "disable-multipart", + Usage: "disable multipart upload feature", + }, cli.StringSliceFlag{ Name: "exclude", Usage: "exclude object(s) that match specified object name pattern", @@ -201,6 +209,7 @@ type mirrorJob struct { isFake, isRemove, isOverwrite bool isWatch, isPreserve bool + md5, disableMultipart bool olderThan, newerThan string storageClass string userMetadata map[string]string @@ -321,6 +330,8 @@ func (mj *mirrorJob) doMirror(ctx context.Context, cancelMirror context.CancelFu TotalCount: sURLs.TotalCount, TotalSize: sURLs.TotalSize, }) + sURLs.MD5 = mj.md5 + sURLs.DisableMultipart = mj.disableMultipart return uploadSourceToTargetURL(ctx, sURLs, mj.status, mj.encKeyDB, mj.isPreserve) } @@ -428,9 +439,11 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance Time: sourceModTime, Metadata: event.UserMetadata, }, - TargetAlias: targetAlias, - TargetContent: &ClientContent{URL: *targetURL}, - encKeyDB: mj.encKeyDB, + TargetAlias: targetAlias, + TargetContent: &ClientContent{URL: *targetURL}, + MD5: mj.md5, + DisableMultipart: mj.disableMultipart, + encKeyDB: mj.encKeyDB, } if mj.multiMasterEnable && mirrorURL.SourceContent.Metadata[multiMasterSourceModTimeKey] != "" { @@ -505,11 +518,13 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance continue } mirrorURL := URLs{ - SourceAlias: sourceAlias, - SourceContent: nil, - TargetAlias: targetAlias, - TargetContent: &ClientContent{URL: *targetURL}, - encKeyDB: mj.encKeyDB, + SourceAlias: sourceAlias, + SourceContent: nil, + TargetAlias: targetAlias, + TargetContent: &ClientContent{URL: *targetURL}, + MD5: mj.md5, + DisableMultipart: mj.disableMultipart, + encKeyDB: mj.encKeyDB, } mirrorURL.TotalCount = mj.status.GetCounts() mirrorURL.TotalSize = mj.status.Get() @@ -644,7 +659,10 @@ func (mj *mirrorJob) mirror(ctx context.Context, cancelMirror context.CancelFunc return mj.monitorMirrorStatus() } -func newMirrorJob(srcURL, dstURL string, isFake, isRemove, isOverwrite, isWatch, isPreserve bool, multiMasterEnable bool, excludeOptions []string, olderThan, newerThan, storageClass string, userMetadata map[string]string, encKeyDB map[string][]prefixSSEPair) *mirrorJob { +func newMirrorJob(srcURL, dstURL string, isFake, isRemove, isOverwrite, isWatch, isPreserve, multiMasterEnable bool, excludeOptions []string, olderThan, newerThan string, storageClass string, userMetadata map[string]string, encKeyDB map[string][]prefixSSEPair, md5, disableMultipart bool) *mirrorJob { + if multiMasterEnable { + isPreserve = true + } mj := mirrorJob{ stopCh: make(chan struct{}), @@ -656,6 +674,8 @@ func newMirrorJob(srcURL, dstURL string, isFake, isRemove, isOverwrite, isWatch, isOverwrite: isOverwrite, isWatch: isWatch, isPreserve: isPreserve || multiMasterEnable, + md5: md5, + disableMultipart: disableMultipart, excludeOptions: excludeOptions, olderThan: olderThan, newerThan: newerThan, @@ -783,7 +803,10 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr ctx.String("newer-than"), ctx.String("storage-class"), userMetaMap, - encKeyDB) + encKeyDB, + ctx.Bool("md5"), + ctx.Bool("disable-multipart"), + ) go func() { <-globalContext.Done() diff --git a/cmd/pipe-main.go b/cmd/pipe-main.go index ae7df770..4854c87b 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, false) + _, err := putTargetStreamWithURL(targetURL, os.Stdin, -1, sseKey, false, 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 61def1db..9e21bae6 100644 --- a/cmd/urls.go +++ b/cmd/urls.go @@ -28,6 +28,7 @@ type URLs struct { TargetContent *ClientContent TotalCount int64 TotalSize int64 + MD5 bool DisableMultipart bool encKeyDB map[string][]prefixSSEPair Error *probe.Error `json:"-"`