Properly stop parallel work in mirror/cp when the user clicks on Ctrl-C (#2437)
This commit is contained in:
+7
-7
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user