Skip to content

Commit

Permalink
Fix 'panic()' on 'Pull' goroutines (:warning: We need more tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Oct 3, 2017
1 parent 9a32ee9 commit d97d5a6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func main() {
fmt.Printf(format, "<STATE>", "<DIGEST>", "<(local) ID>", "<Created At>", "<TAG>")

repoCount := len(o.Positional.Repositories)
pullCount := 0

type tagResult struct {
Tags []*tag.Tag
Expand Down Expand Up @@ -203,6 +204,10 @@ func main() {
continue
}

if tg.NeedsPull() {
pullCount++
}

tags = append(tags, tg)
}

Expand Down Expand Up @@ -234,7 +239,7 @@ func main() {
}

if o.Pull {
done := make(chan bool, repoCount)
done := make(chan bool, pullCount)

for _, tr := range tagResults {
go func(tags []*tag.Tag, repo string, done chan bool) {
Expand All @@ -247,19 +252,22 @@ func main() {
if err != nil {
suicide(err)
}

done <- true
}

done <- true
}
}(tr.Tags, tr.Repo, done)
}

repoNumber := 0
for range done {
repoNumber++
pullNumber := 0
if pullCount > 0 {
for range done {
pullNumber++

if repoNumber >= repoCount {
close(done)
if pullNumber >= pullCount {
close(done)
}
}
}
}
Expand Down

0 comments on commit d97d5a6

Please sign in to comment.