yay/pkg/query/aur_info.go
Jo 0bf4c2e502
feat(new_install): show (#1915)
* show new packages in upgrade form if they exist

* refactor up select

* remove unused graph parts

* readd len

* Complete upgrade graphing

* Extract to upgrade pkg

* remove unused dep method

* remove uneeded dep

* cleanup method

* specify io Reader for testing

* use specified input vector

* fix non-active devel

* test base cases

* add devel test cases

* add range tests

* add logger struct

* use logger struct in upgrade

* follow golangci recommendations

* update deps

* update golangci
2023-02-17 19:01:26 +00:00

101 lines
2.1 KiB
Go

package query
import (
"context"
"sync"
"github.com/Jguer/aur"
"github.com/leonelquinteros/gotext"
"github.com/Jguer/yay/v11/pkg/intrange"
"github.com/Jguer/yay/v11/pkg/multierror"
"github.com/Jguer/yay/v11/pkg/text"
)
type Pkg = aur.Pkg
// Queries the aur for information about specified packages.
// All packages should be queried in a single aur request except when the number
// of packages exceeds the number set in config.RequestSplitN.
// If the number does exceed config.RequestSplitN multiple aur requests will be
// performed concurrently.
func AURInfo(ctx context.Context, aurClient aur.ClientInterface, names []string, warnings *AURWarnings, splitN int) ([]Pkg, error) {
info := make([]Pkg, 0, len(names))
seen := make(map[string]int)
var (
mux sync.Mutex
wg sync.WaitGroup
errs multierror.MultiError
)
makeRequest := func(n, max int) {
defer wg.Done()
text.Debugln("AUR RPC:", names[n:max])
tempInfo, requestErr := aurClient.Info(ctx, names[n:max])
if requestErr != nil {
errs.Add(requestErr)
return
}
mux.Lock()
info = append(info, tempInfo...)
mux.Unlock()
}
for n := 0; n < len(names); n += splitN {
max := intrange.Min(len(names), n+splitN)
wg.Add(1)
go makeRequest(n, max)
}
wg.Wait()
if err := errs.Return(); err != nil {
return info, err
}
for k := range info {
seen[info[k].Name] = k
}
for _, name := range names {
i, ok := seen[name]
if !ok && !warnings.Ignore.Get(name) {
warnings.Missing = append(warnings.Missing, name)
continue
}
pkg := info[i]
if pkg.Maintainer == "" && !warnings.Ignore.Get(name) {
warnings.Orphans = append(warnings.Orphans, name)
}
if pkg.OutOfDate != 0 && !warnings.Ignore.Get(name) {
warnings.OutOfDate = append(warnings.OutOfDate, name)
}
}
return info, nil
}
func AURInfoPrint(ctx context.Context, aurClient aur.ClientInterface, names []string, splitN int) ([]Pkg, error) {
text.OperationInfoln(gotext.Get("Querying AUR..."))
warnings := &AURWarnings{}
info, err := AURInfo(ctx, aurClient, names, warnings, splitN)
if err != nil {
return info, err
}
warnings.Print()
return info, nil
}