From db679e58ff79781207d9ce346a94f6fffbef436a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 13 Jul 2015 21:42:26 -0700 Subject: [PATCH] Add syncQueue, cpQueue back into defer --- Godeps/Godeps.json | 4 ++-- .../src/github.com/minio/minio-go/api.go | 20 ++++++++++++++++--- cmd-cp.go | 7 ++++--- cmd-sync.go | 14 ++++++------- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 42a6b08e..95e51eb3 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -28,8 +28,8 @@ }, { "ImportPath": "github.com/minio/minio-go", - "Comment": "v0.1.0-19-g198c130", - "Rev": "198c13010e7ef0b0683db9752c997838d14c1561" + "Comment": "v0.1.0-20-g58c3be1", + "Rev": "58c3be19cd8de7e3f55a14e5cfa1c0ba55aa068d" }, { "ImportPath": "github.com/minio/minio/pkg/iodine", diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/api.go b/Godeps/_workspace/src/github.com/minio/minio-go/api.go index cf0ab861..42d3576a 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/api.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/api.go @@ -25,6 +25,7 @@ import ( "runtime" "sort" "strings" + "sync" "time" ) @@ -188,6 +189,7 @@ func (c *Config) SetUserAgent(name string, version string, comments ...string) { } type api struct { + *sync.Mutex lowLevelAPI } @@ -202,7 +204,7 @@ func New(config Config) (API, error) { } config.SetUserAgent(LibraryName, LibraryVersion, runtime.GOOS, runtime.GOARCH) config.isUserAgentSet = false // default - return api{lowLevelAPI{&config}}, nil + return api{&sync.Mutex{}, lowLevelAPI{&config}}, nil } /// Object operations @@ -473,6 +475,8 @@ func (a api) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch ch // // This version of PutObject automatically does multipart for more than 5MB worth of data func (a api) PutObject(bucket, object, contentType string, size int64, data io.Reader) error { + a.Lock() + defer a.Unlock() if err := invalidBucketToError(bucket); err != nil { return err } @@ -506,9 +510,15 @@ func (a api) PutObject(bucket, object, contentType string, size int64, data io.R } } if !inProgress { - return a.newObjectUpload(bucket, object, contentType, size, data) + if err := a.newObjectUpload(bucket, object, contentType, size, data); err != nil { + return err + } + return nil } - return a.continueObjectUpload(bucket, object, inProgressUploadID, size, data) + if err := a.continueObjectUpload(bucket, object, inProgressUploadID, size, data); err != nil { + return err + } + return nil } return errors.New("Unexpected control flow, please report this error at https://github.com/minio/minio-go/issues") } @@ -555,6 +565,8 @@ func (a api) RemoveObject(bucket, object string) error { // [ us-west-1 | us-west-2 | eu-west-1 | eu-central-1 | ap-southeast-1 | ap-northeast-1 | ap-southeast-2 | sa-east-1 ] // Default - US standard func (a api) MakeBucket(bucket string, acl BucketACL) error { + a.Lock() + defer a.Unlock() if err := invalidBucketToError(bucket); err != nil { return err } @@ -581,6 +593,8 @@ func (a api) MakeBucket(bucket string, acl BucketACL) error { // authenticated-read - owner gets full access, authenticated users get read access // func (a api) SetBucketACL(bucket string, acl BucketACL) error { + a.Lock() + defer a.Unlock() if err := invalidBucketToError(bucket); err != nil { return err } diff --git a/cmd-cp.go b/cmd-cp.go index f672e740..d941d37b 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -73,6 +73,9 @@ EXAMPLES: // doCopy - Copy a singe file from source to destination func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup) error { defer wg.Done() // Notify that this copy routine is done. + defer func() { + <-cpQueue + }() if !globalQuietFlag || !globalJSONFlag { bar.SetCaption(cpURLs.SourceContent.Name + ": ") @@ -105,10 +108,8 @@ func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup if !globalQuietFlag || !globalJSONFlag { bar.ErrorPut(length) } - return iodine.New(err, map[string]string{"URL": cpURLs.TargetContent.Name}) + console.Errorln(iodine.ToError(err)) } - - <-cpQueue // Notify the copy queue that it is free to pickup next routine. return nil } diff --git a/cmd-sync.go b/cmd-sync.go index 3406e86f..b35230ff 100644 --- a/cmd-sync.go +++ b/cmd-sync.go @@ -72,6 +72,9 @@ EXAMPLES: // doSync - Sync an object to multiple destination func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGroup) (err error) { defer wg.Done() // Notify that this copy routine is done. + defer func() { + <-syncQueue + }() if !globalQuietFlag || !globalJSONFlag { bar.SetCaption(sURLs.SourceContent.Name + ": ") @@ -81,11 +84,11 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou if err != nil { if !globalQuietFlag || !globalJSONFlag { bar.ErrorGet(int64(length)) - console.Errors(ErrorMessage{ - Message: "Failed with", - Error: iodine.New(err, nil), - }) } + console.Errors(ErrorMessage{ + Message: "Failed with", + Error: iodine.New(err, nil), + }) } var targetURLs []string @@ -113,9 +116,6 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou } } } - - <-syncQueue // Notify the copy queue that it is free to pickup next routine. - return nil }