Use MultiError in other goroutines

This commit is contained in:
morganamilo 2018-08-02 17:14:57 +01:00
parent ff5ed12181
commit b3e647aee4
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 15 additions and 27 deletions

View file

@ -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()
@ -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
}

View file

@ -3,7 +3,6 @@ package main
import (
"fmt"
"sort"
"strings"
"sync"
"unicode"
@ -109,7 +108,7 @@ 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
@ -117,9 +116,10 @@ func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {
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)
@ -127,7 +127,8 @@ func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {
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()
}()
}
@ -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()
}()
@ -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 {
@ -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) {