From 420b5d286c208c48e1b71bc677b27e8bce25d414 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 13 Jul 2015 16:08:32 -0700 Subject: [PATCH] Fix hangs in cp and sync with --quiet and json flag --- cmd-cp.go | 14 ++++++-------- cmd-sync.go | 15 ++++++--------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/cmd-cp.go b/cmd-cp.go index 5f1e5546..84f1471c 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -73,17 +73,14 @@ 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() { // Notify the copy queue that it is free to pickup next routine. - <-cpQueue - }() - if !globalQuietFlag { + if !globalQuietFlag || !globalJSONFlag { bar.SetCaption(cpURLs.SourceContent.Name + ": ") } reader, length, err := getSource(cpURLs.SourceContent.Name) if err != nil { - if !globalQuietFlag { + if !globalQuietFlag || !globalJSONFlag { bar.ErrorGet(length) } return iodine.New(err, map[string]string{"URL": cpURLs.SourceContent.Name}) @@ -105,12 +102,14 @@ func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup err = putTarget(cpURLs.TargetContent.Name, length, newReader) if err != nil { - if !globalQuietFlag { + if !globalQuietFlag || !globalJSONFlag { bar.ErrorPut(length) } return iodine.New(err, map[string]string{"URL": cpURLs.TargetContent.Name}) } + <-cpQueue // Notify the copy queue that it is free to pickup next routine. + return nil } @@ -186,11 +185,10 @@ func doCopyCmdSession(session *sessionV2) { defer close(cpQueue) scanner := bufio.NewScanner(session.NewDataReader()) - isCopied := isCopiedFactory(session.Header.LastCopied) var bar barSend - if !globalQuietFlag { // set up progress bar + if !globalQuietFlag || !globalJSONFlag { // set up progress bar bar = newCpBar() defer bar.Finish() bar.Extend(session.Header.TotalBytes) diff --git a/cmd-sync.go b/cmd-sync.go index 387c7bad..b1ea6395 100644 --- a/cmd-sync.go +++ b/cmd-sync.go @@ -72,17 +72,14 @@ 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() { // Notify the copy queue that it is free to pickup next routine. - <-syncQueue - }() - if !globalQuietFlag { + if !globalQuietFlag || !globalJSONFlag { bar.SetCaption(sURLs.SourceContent.Name + ": ") } reader, length, err := getSource(sURLs.SourceContent.Name) if err != nil { - if !globalQuietFlag { + if !globalQuietFlag || !globalJSONFlag { bar.ErrorGet(int64(length)) console.Errors(ErrorMessage{ Message: "Failed with", @@ -111,12 +108,14 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou for err := range putTargets(targetURLs, length, newReader) { if err != nil { - if !globalQuietFlag { + if !globalQuietFlag || !globalJSONFlag { bar.ErrorPut(int64(length)) } } } + <-syncQueue // Notify the copy queue that it is free to pickup next routine. + return nil } @@ -189,15 +188,13 @@ func doSyncCmdSession(session *sessionV2) { defer close(syncQueue) scanner := bufio.NewScanner(session.NewDataReader()) - isCopied := isCopiedFactory(session.Header.LastCopied) var bar barSend - if !globalQuietFlag { // set up progress bar + if !globalQuietFlag || !globalJSONFlag { // set up progress bar bar = newCpBar() defer bar.Finish() bar.Extend(session.Header.TotalBytes) - } for scanner.Scan() {