Properly stop parallel work in mirror/cp when the user clicks on Ctrl-C (#2437)

This commit is contained in:
Anis Elleuch
2018-04-25 11:55:07 -07:00
committed by Dee Koder
parent 2dc48e9dd3
commit 1ccf40d1e5
2 changed files with 13 additions and 9 deletions
+7 -7
View File
@@ -317,7 +317,11 @@ func doCopySession(session *sessionV8) error {
var statusCh = make(chan URLs)
p, queueCh := newParallelManager(statusCh, pg)
parallel, queueCh := newParallelManager(statusCh, pg)
stopParallel := func() {
close(queueCh)
parallel.wait()
}
go func() {
// Loop through all urls.
@@ -352,12 +356,7 @@ func doCopySession(session *sessionV8) error {
}
}
// URLs feeding finished
close(queueCh)
// Wait for all tasks to be finished
p.wait()
stopParallel()
close(statusCh)
}()
@@ -368,6 +367,7 @@ loop:
for {
select {
case <-trapCh:
stopParallel()
cancelCopy()
// Receive interrupt notification.
if !globalQuiet && !globalJSON {
+6 -2
View File
@@ -479,6 +479,10 @@ func (mj *mirrorJob) startMirror(ctx context.Context, cancelMirror context.Cance
var totalObjects int64
parallel, queueCh := newParallelManager(mj.statusCh, mj.status)
stopParallel := func() {
close(queueCh)
parallel.wait()
}
URLsCh := prepareMirrorURLs(mj.sourceURL, mj.targetURL, mj.isFake, mj.isOverwrite, mj.isRemove, mj.excludeOptions, mj.encKeyDB)
@@ -486,8 +490,7 @@ func (mj *mirrorJob) startMirror(ctx context.Context, cancelMirror context.Cance
select {
case sURLs, ok := <-URLsCh:
if !ok {
close(queueCh)
parallel.wait()
stopParallel()
errCh <- nil
return
}
@@ -531,6 +534,7 @@ func (mj *mirrorJob) startMirror(ctx context.Context, cancelMirror context.Cance
}
}
case <-mj.trapCh:
stopParallel()
cancelMirror()
errCh <- nil
return