Skip to content

Commit

Permalink
Fixing infinite loop :o
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlocph committed Jul 17, 2019
1 parent e22d41d commit e2b76ac
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions remote/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"regexp"
"strconv"
"strings"
"sync"

"github.com/laszlocph/drone-oss-08/model"
"github.com/laszlocph/drone-oss-08/remote"
Expand Down Expand Up @@ -253,9 +252,6 @@ func (c *client) Dir(u *model.User, r *model.Repo, b *model.Build, f string) ([]
fc := make(chan *remote.FileMeta)
errc := make(chan error)

wg := &sync.WaitGroup{}
wg.Add(len(data))

for _, file := range data {
go func(path string) {
content, err := c.File(u, r, b, path)
Expand All @@ -273,24 +269,15 @@ func (c *client) Dir(u *model.User, r *model.Repo, b *model.Build, f string) ([]
var files []*remote.FileMeta
var errors []error

go func() {
for {
select {
case err, open := <-errc:
if open {
errors = append(errors, err)
wg.Done()
}
case fileMeta, open := <-fc:
if open {
files = append(files, fileMeta)
wg.Done()
}
}
for i := 0; i < len(data); i++ {
select {
case err, _ := <-errc:
errors = append(errors, err)
case fileMeta, _ := <-fc:
files = append(files, fileMeta)
}
}()
}

wg.Wait()
close(fc)
close(errc)

Expand Down

0 comments on commit e2b76ac

Please sign in to comment.