2020-07-10 02:36:45 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
2021-05-13 07:27:24 +02:00
|
|
|
"context"
|
2020-07-10 02:36:45 +02:00
|
|
|
"sync"
|
|
|
|
|
2021-05-13 07:27:24 +02:00
|
|
|
"github.com/Jguer/aur"
|
2023-02-20 12:20:48 +01:00
|
|
|
"github.com/Jguer/aur/rpc"
|
2020-07-10 02:36:45 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/intrange"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/multierror"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/text"
|
2020-07-10 02:36:45 +02:00
|
|
|
)
|
|
|
|
|
2021-05-13 07:27:24 +02:00
|
|
|
type Pkg = aur.Pkg
|
2021-02-16 16:10:04 +01:00
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
// Queries the aur for information about specified packages.
|
2021-05-13 07:27:24 +02:00
|
|
|
// All packages should be queried in a single aur request except when the number
|
2020-07-10 02:36:45 +02:00
|
|
|
// of packages exceeds the number set in config.RequestSplitN.
|
2021-05-13 07:27:24 +02:00
|
|
|
// If the number does exceed config.RequestSplitN multiple aur requests will be
|
2020-07-10 02:36:45 +02:00
|
|
|
// performed concurrently.
|
2023-02-20 12:20:48 +01:00
|
|
|
func AURInfo(ctx context.Context, aurClient rpc.ClientInterface, names []string, warnings *AURWarnings, splitN int) ([]Pkg, error) {
|
2022-12-29 19:42:43 +01:00
|
|
|
info := make([]Pkg, 0, len(names))
|
2020-07-10 02:36:45 +02:00
|
|
|
seen := make(map[string]int)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
|
|
|
var (
|
|
|
|
mux sync.Mutex
|
|
|
|
wg sync.WaitGroup
|
|
|
|
errs multierror.MultiError
|
|
|
|
)
|
2020-07-10 02:36:45 +02:00
|
|
|
|
|
|
|
makeRequest := func(n, max int) {
|
|
|
|
defer wg.Done()
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2022-11-13 23:53:37 +01:00
|
|
|
text.Debugln("AUR RPC:", names[n:max])
|
2022-11-15 15:44:50 +01:00
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
tempInfo, requestErr := aurClient.Info(ctx, names[n:max])
|
2020-07-10 02:36:45 +02:00
|
|
|
if requestErr != nil {
|
2021-08-11 20:13:28 +02:00
|
|
|
errs.Add(requestErr)
|
2020-07-10 02:36:45 +02:00
|
|
|
return
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
mux.Lock()
|
2023-02-17 20:01:26 +01:00
|
|
|
info = append(info, tempInfo...)
|
2020-07-10 02:36:45 +02:00
|
|
|
mux.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
for n := 0; n < len(names); n += splitN {
|
|
|
|
max := intrange.Min(len(names), n+splitN)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
wg.Add(1)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
go makeRequest(n, max)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
if err := errs.Return(); err != nil {
|
|
|
|
return info, err
|
|
|
|
}
|
|
|
|
|
2022-12-29 19:42:43 +01:00
|
|
|
for k := range info {
|
|
|
|
seen[info[k].Name] = k
|
2020-07-10 02:36:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
if pkg.OutOfDate != 0 && !warnings.Ignore.Get(name) {
|
|
|
|
warnings.OutOfDate = append(warnings.OutOfDate, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return info, nil
|
|
|
|
}
|
|
|
|
|
2023-02-20 12:20:48 +01:00
|
|
|
func AURInfoPrint(ctx context.Context, aurClient rpc.ClientInterface, names []string, splitN int) ([]Pkg, error) {
|
2020-07-10 02:36:45 +02:00
|
|
|
text.OperationInfoln(gotext.Get("Querying AUR..."))
|
|
|
|
|
2023-04-11 18:45:20 +02:00
|
|
|
warnings := NewWarnings(nil)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
info, err := AURInfo(ctx, aurClient, names, warnings, splitN)
|
2020-07-10 02:36:45 +02:00
|
|
|
if err != nil {
|
|
|
|
return info, err
|
|
|
|
}
|
|
|
|
|
|
|
|
warnings.Print()
|
|
|
|
|
|
|
|
return info, nil
|
|
|
|
}
|