add --disable-multipart flag in cp (#3135)
This commit is contained in:
+1
-1
@@ -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"])
|
||||
|
||||
@@ -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)))
|
||||
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
@@ -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)))
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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()))
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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:
|
||||
|
||||
+9
-8
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user