Skip to content

Commit

Permalink
Use MultiError in other goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
Morganamilo committed Aug 9, 2018
1 parent ff5ed12 commit b3e647a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
9 changes: 3 additions & 6 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,13 @@ func aurInfo(names []string, warnings *aurWarnings) ([]*rpc.Pkg, error) {
seen := make(map[string]int)
var mux sync.Mutex
var wg sync.WaitGroup
var err error
var errs MultiError

makeRequest := func(n, max int) {
defer wg.Done()
tempInfo, requestErr := rpc.Info(names[n:max])
if err != nil {
return
}
errs.Add(requestErr)
if requestErr != nil {
err = requestErr
return
}
mux.Lock()
Expand All @@ -505,7 +502,7 @@ func aurInfo(names []string, warnings *aurWarnings) ([]*rpc.Pkg, error) {

wg.Wait()

if err != nil {
if err := errs.Return(); err != nil {
return info, err
}

Expand Down
33 changes: 12 additions & 21 deletions upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"sort"
"strings"
"sync"
"unicode"

Expand Down Expand Up @@ -109,25 +108,27 @@ func getVersionDiff(oldVersion, newVersion string) (left, right string) {
}

// upList returns lists of packages to upgrade from each source.
func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {
func upList(warnings *aurWarnings) (upSlice, upSlice, error) {
local, remote, _, remoteNames, err := filterPackages()
if err != nil {
return nil, nil, err
}

var wg sync.WaitGroup
var develUp upSlice
var repoUp upSlice
var aurUp upSlice

var repoErr error
var aurErr error
var errs MultiError

aurdata := make(map[string]*rpc.Pkg)

if mode == ModeAny || mode == ModeRepo {
fmt.Println(bold(cyan("::") + bold(" Searching databases for updates...")))
wg.Add(1)
go func() {
repoUp, repoErr = upRepo(local)
repoUp, err = upRepo(local)
errs.Add(err)
wg.Done()
}()
}
Expand All @@ -136,15 +137,17 @@ func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {
fmt.Println(bold(cyan("::") + bold(" Searching AUR for updates...")))

var _aurdata []*rpc.Pkg
_aurdata, aurErr = aurInfo(remoteNames, warnings)
if aurErr == nil {
_aurdata, err = aurInfo(remoteNames, warnings)
errs.Add(err)
if err == nil {
for _, pkg := range _aurdata {
aurdata[pkg.Name] = pkg
}

wg.Add(1)
go func() {
aurUp, aurErr = upAUR(remote, aurdata)
aurUp, err = upAUR(remote, aurdata)
errs.Add(err)
wg.Done()
}()

Expand All @@ -163,18 +166,6 @@ func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {

printLocalNewerThanAUR(remote, aurdata)

errs := make([]string, 0)
for _, e := range []error{repoErr, aurErr} {
if e != nil {
errs = append(errs, e.Error())
}
}

if len(errs) > 0 {
err = fmt.Errorf("%s", strings.Join(errs, "\n"))
return nil, nil, err
}

if develUp != nil {
names := make(stringSet)
for _, up := range develUp {
Expand All @@ -189,7 +180,7 @@ func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {
aurUp = develUp
}

return aurUp, repoUp, err
return aurUp, repoUp, errs.Return()
}

func upDevel(remote []alpm.Package, aurdata map[string]*rpc.Pkg) (toUpgrade upSlice) {
Expand Down

0 comments on commit b3e647a

Please sign in to comment.