Merge pull request #1316 from harshavardhana/put-object

cp/mirror: Now putObject does single Put for 0byte sized files
This commit is contained in:
Harshavardhana
2015-11-14 23:32:02 -08:00
4 changed files with 22 additions and 10 deletions
+3 -3
View File
@@ -57,7 +57,7 @@ func getSource(sourceURL string) (reader io.ReadCloser, length int64, err *probe
return sourceClnt.Get(0, 0)
}
// putTarget writes to URL from reader. If length=0, read until EOF.
// putTarget writes to URL from reader. If length=-1, read until EOF.
func putTarget(targetURL string, length int64, reader io.Reader) *probe.Error {
targetClnt, err := url2Client(targetURL)
if err != nil {
@@ -70,7 +70,7 @@ func putTarget(targetURL string, length int64, reader io.Reader) *probe.Error {
return nil
}
// putTargets writes to URL from reader. If length=0, read until EOF.
// putTargets writes to URL from reader. If length=-1, read until EOF.
func putTargets(targetURLs []string, length int64, reader io.Reader) *probe.Error {
var tgtReaders []*io.PipeReader
var tgtWriters []*io.PipeWriter
@@ -98,7 +98,7 @@ func putTargets(targetURLs []string, length int64, reader io.Reader) *probe.Erro
multiTgtWriter := io.MultiWriter(writers...)
var e error
switch length {
case 0:
case -1:
_, e = io.Copy(multiTgtWriter, reader)
default:
_, e = io.CopyN(multiTgtWriter, reader, length)
+3 -2
View File
@@ -57,8 +57,9 @@ func checkPipeSyntax(ctx *cli.Context) {
// pipe writes contents of stdin a collection of URLs.
func pipe(targetURLs []string) *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 := putTargets(targetURLs, 0, os.Stdin)
// Ignore size, since os.Stat() would not return proper size all the time
// for local filesystem for example /proc files.
err := putTargets(targetURLs, -1, os.Stdin)
// TODO: See if this check is necessary.
switch e := err.ToGoError().(type) {
case *os.PathError:
+14 -3
View File
@@ -640,7 +640,18 @@ func (a API) continueObjectUpload(bucket, object, uploadID string, size int64, d
//
// You must have WRITE permissions on a bucket to create an object.
//
// This version of PutObject automatically does multipart for more than 5MB worth of data.
// - For size lesser than 5MB PutObject automatically does single Put operation.
// - For size equal to 0Bytes PutObject automatically does single Put operation.
// - For size larger than 5MB PutObject automatically does resumable multipart operation.
// - For size input as -1 PutObject treats it as a stream and does multipart operation until
// input stream reaches EOF.
//
// NOTE: if you are using Google Cloud Storage. Then there is no resumable multipart
// upload support yet. Currently PutObject will behave like a single PUT operation and would
// only upload for file sizes upto maximum 5GB. (maximum limit for single PUT operation).
//
// For un-authenticated requests S3 doesn't allow multipart upload, so we fall back to single
// PUT operation.
func (a API) PutObject(bucket, object, contentType string, size int64, data io.Reader) error {
if err := invalidBucketError(bucket); err != nil {
return err
@@ -677,7 +688,7 @@ func (a API) PutObject(bucket, object, contentType string, size int64, data io.R
return nil
}
switch {
case size < minimumPartSize && size > 0:
case size < minimumPartSize && size >= 0:
// Single Part use case, use PutObject directly.
for part := range chopper(data, minimumPartSize, nil) {
if part.Err != nil {
@@ -697,7 +708,7 @@ func (a API) PutObject(bucket, object, contentType string, size int64, data io.R
}
return nil
}
default:
case size >= minimumPartSize || size == -1:
var inProgress bool
var inProgressUploadID string
for mpUpload := range a.listMultipartUploadsRecursive(bucket, object) {
+2 -2
View File
@@ -29,8 +29,8 @@
},
{
"path": "github.com/minio/minio-go",
"revision": "5eb302c71339c00f6a895f2dca133395227c0fae",
"revisionTime": "2015-11-13T19:53:11-08:00"
"revision": "f3e8175c352db0fe318c1e8db19f167fa83c60e3",
"revisionTime": "2015-11-14T23:15:05-08:00"
},
{
"path": "github.com/minio/minio-xl/pkg/probe",