forked from TrueCloudLab/restic
delete: properly close fileChan if context is canceled
This commit is contained in:
parent
38ccddc84f
commit
5767c65c62
1 changed files with 10 additions and 5 deletions
|
@ -25,16 +25,21 @@ const numDeleteWorkers = 8
|
||||||
func deleteFiles(gopts GlobalOptions, ignoreError bool, repo restic.Repository, fileList restic.IDSet, fileType restic.FileType) error {
|
func deleteFiles(gopts GlobalOptions, ignoreError bool, repo restic.Repository, fileList restic.IDSet, fileType restic.FileType) error {
|
||||||
totalCount := len(fileList)
|
totalCount := len(fileList)
|
||||||
fileChan := make(chan restic.ID)
|
fileChan := make(chan restic.ID)
|
||||||
go func() {
|
wg, ctx := errgroup.WithContext(gopts.ctx)
|
||||||
|
wg.Go(func() error {
|
||||||
|
defer close(fileChan)
|
||||||
for id := range fileList {
|
for id := range fileList {
|
||||||
fileChan <- id
|
select {
|
||||||
|
case fileChan <- id:
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close(fileChan)
|
return nil
|
||||||
}()
|
})
|
||||||
|
|
||||||
bar := newProgressMax(!gopts.JSON && !gopts.Quiet, uint64(totalCount), "files deleted")
|
bar := newProgressMax(!gopts.JSON && !gopts.Quiet, uint64(totalCount), "files deleted")
|
||||||
defer bar.Done()
|
defer bar.Done()
|
||||||
wg, ctx := errgroup.WithContext(gopts.ctx)
|
|
||||||
for i := 0; i < numDeleteWorkers; i++ {
|
for i := 0; i < numDeleteWorkers; i++ {
|
||||||
wg.Go(func() error {
|
wg.Go(func() error {
|
||||||
for id := range fileChan {
|
for id := range fileChan {
|
||||||
|
|
Loading…
Add table
Reference in a new issue