Skip to content

Commit

Permalink
feat(aur): customize User Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Jun 9, 2021
1 parent 6e70e2a commit 545ea77
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 102 deletions.
2 changes: 1 addition & 1 deletion clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func cleanAUR(keepInstalled, keepCurrent, removeAll bool, dbExecutor db.Executor
// Querying the AUR is slow and needs internet so don't do it if we
// don't need to.
if keepCurrent {
info, errInfo := query.AURInfo(cachedPackages, &query.AURWarnings{}, config.RequestSplitN)
info, errInfo := query.AURInfo(config.Runtime.AURClient, cachedPackages, &query.AURWarnings{}, config.RequestSplitN)
if errInfo != nil {
return errInfo
}
Expand Down
4 changes: 2 additions & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func handleSync(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
} else {
config.SearchMode = detailed
}
return syncSearch(targets, dbExecutor)
return syncSearch(targets, config.Runtime.AURClient, dbExecutor)
}
if cmdArgs.ExistsArg("p", "print", "print-format") {
return config.Runtime.CmdRunner.Show(passToPacman(cmdArgs))
Expand Down Expand Up @@ -341,7 +341,7 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *settings.
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)

if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
aq, aurErr = narrowSearch(pkgS, true)
aq, aurErr = narrowSearch(config.Runtime.AURClient, pkgS, true)
lenaq = len(aq)
}
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
Expand Down
2 changes: 1 addition & 1 deletion download.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func getPkgbuilds(pkgs []string, dbExecutor db.Executor, force bool) error {
aur[n] = pkg
}

info, err := query.AURInfoPrint(aur, config.RequestSplitN)
info, err := query.AURInfoPrint(config.Runtime.AURClient, aur, config.RequestSplitN)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module github.com/Jguer/yay/v10

require (
github.com/Jguer/aur v0.0.0-20210511064249-3d6117992c83
github.com/Jguer/go-alpm/v2 v2.0.5
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5
github.com/Morganamilo/go-srcinfo v1.0.0
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/leonelquinteros/gotext v1.4.0
github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656
github.com/leonelquinteros/gotext v1.5.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
golang.org/x/text v0.3.6 // indirect
gopkg.in/h2non/gock.v1 v1.0.15
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

go 1.14
25 changes: 23 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
github.com/Jguer/aur v0.0.0-20210510203355-38871b878ace h1:7ImlMwhRXVtuE+4jjEut4GCdNUGFyuytQUIxyCyy218=
github.com/Jguer/aur v0.0.0-20210510203355-38871b878ace/go.mod h1:1/SQjhWahmk2xKcmAm6XO1zGqK8HgYw3xlJM6a7845E=
github.com/Jguer/aur v0.0.0-20210511064249-3d6117992c83 h1:UtnJ3lvuidbG5rwN2tSQe5kVOvhFZRUGNkS6boxgxPk=
github.com/Jguer/aur v0.0.0-20210511064249-3d6117992c83/go.mod h1:1/SQjhWahmk2xKcmAm6XO1zGqK8HgYw3xlJM6a7845E=
github.com/Jguer/go-alpm/v2 v2.0.5 h1:1TZxkvCIfTOhjhxGy/Z1FNSeuY9DXBKF5qxUoj0IZ0A=
github.com/Jguer/go-alpm/v2 v2.0.5/go.mod h1:zU4iKCtNkDARfj5BrKJXYAQ5nIjtZbySfa0paboSmTQ=
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5 h1:TMscPjkb1ThXN32LuFY5bEYIcXZx3YlwzhS1GxNpn/c=
Expand All @@ -13,22 +17,39 @@ github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslC
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/leonelquinteros/gotext v1.4.0 h1:2NHPCto5IoMXbrT0bldPrxj0qM5asOCwtb1aUQZ1tys=
github.com/leonelquinteros/gotext v1.4.0/go.mod h1:yZGXREmoGTtBvZHNcc+Yfug49G/2spuF/i/Qlsvz1Us=
github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656 h1:j679+jxcDkCFblYk+I+G71HQTFxM3PacYbVCiYmhRhU=
github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656/go.mod h1:nYOKcK8tIj69ZZ8uDOWoiT+L25NvlOQaraDqTec/idA=
github.com/leonelquinteros/gotext v1.5.0 h1:ODY7LzLpZWWSJdAHnzhreOr6cwLXTAmc914FOauSkBM=
github.com/leonelquinteros/gotext v1.5.0/go.mod h1:OCiUVHuhP9LGFBQ1oAmdtNCHJCiHiQA8lf4nAifHkr0=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 h1:5PbJGn5Sp3GEUjJ61aYbUP6RIo3Z3r2E4Tv9y2z8UHo=
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mUOKexJBNsLf4Z+6En1Q=
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20200221224223-e1da425f72fd/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0=
Expand Down
2 changes: 1 addition & 1 deletion install.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func install(cmdArgs *settings.Arguments, dbExecutor db.Executor, ignoreProvider
targets := stringset.FromSlice(cmdArgs.Targets)

dp, err := dep.GetPool(requestTargets,
warnings, dbExecutor, config.Runtime.Mode,
warnings, dbExecutor, config.Runtime.AURClient, config.Runtime.Mode,
ignoreProviders, settings.NoConfirm, config.Provides, config.ReBuild, config.RequestSplitN, noDeps, noCheck)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func main() {
text.Warnln(gotext.Get("Avoid running yay as root/sudo."))
}

config, err = settings.NewConfig()
config, err = settings.NewConfig(yayVersion)
if err != nil {
if str := err.Error(); str != "" {
fmt.Fprintln(os.Stderr, str)
Expand Down
6 changes: 3 additions & 3 deletions pkg/dep/base.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dep

import rpc "github.com/Jguer/yay/v10/pkg/query"
import aur "github.com/Jguer/yay/v10/pkg/query"

// Base is an AUR base package
type Base []*rpc.Pkg
type Base []*aur.Pkg

// Pkgbase returns the first base package.
func (b Base) Pkgbase() string {
Expand Down Expand Up @@ -38,7 +38,7 @@ func (b Base) String() string {
return str
}

func GetBases(pkgs []*rpc.Pkg) []Base {
func GetBases(pkgs []*aur.Pkg) []Base {
basesMap := make(map[string]Base)
for _, pkg := range pkgs {
basesMap[pkg.PackageBase] = append(basesMap[pkg.PackageBase], pkg)
Expand Down
8 changes: 4 additions & 4 deletions pkg/dep/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"strings"

"github.com/Jguer/yay/v10/pkg/db"
rpc "github.com/Jguer/yay/v10/pkg/query"
aur "github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/text"
)

type providers struct {
lookfor string
Pkgs []*rpc.Pkg
Pkgs []*aur.Pkg
}

func makeProviders(name string) providers {
return providers{
name,
make([]*rpc.Pkg, 0),
make([]*aur.Pkg, 0),
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func verSatisfies(ver1, mod, ver2 string) bool {
return true
}

func satisfiesAur(dep string, pkg *rpc.Pkg) bool {
func satisfiesAur(dep string, pkg *aur.Pkg) bool {
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
return true
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/dep/depOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/Jguer/yay/v10/pkg/db"
rpc "github.com/Jguer/yay/v10/pkg/query"
aur "github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/stringset"
"github.com/Jguer/yay/v10/pkg/text"
)
Expand Down Expand Up @@ -41,7 +41,7 @@ func GetOrder(dp *Pool, noDeps, noCheckDeps bool) *Order {
return do
}

func (do *Order) orderPkgAur(pkg *rpc.Pkg, dp *Pool, runtime, noDeps, noCheckDeps bool) {
func (do *Order) orderPkgAur(pkg *aur.Pkg, dp *Pool, runtime, noDeps, noCheckDeps bool) {
if runtime {
do.Runtime.Set(pkg.Name)
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (do *Order) GetMake() []string {
func (do *Order) Print() {
repo := ""
repoMake := ""
aur := ""
aurString := ""
aurMake := ""

repoLen := 0
Expand Down Expand Up @@ -172,7 +172,7 @@ func (do *Order) Print() {
}

if push {
aur += pkgStr
aurString += pkgStr
}
if pushMake {
aurMake += pkgStrMake
Expand All @@ -181,7 +181,7 @@ func (do *Order) Print() {

printDownloads("Repo", repoLen, repo)
printDownloads("Repo Make", repoMakeLen, repoMake)
printDownloads("Aur", aurLen, aur)
printDownloads("Aur", aurLen, aurString)
printDownloads("Aur Make", aurMakeLen, aurMake)
}

Expand Down
34 changes: 19 additions & 15 deletions pkg/dep/depPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package dep

import (
"bufio"
"context"
"fmt"
"os"
"sort"
"strconv"
"strings"
"sync"

"github.com/Jguer/aur"
"github.com/Jguer/go-alpm/v2"
"github.com/leonelquinteros/gotext"
"github.com/mikkeloscar/aur"

"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/query"
Expand Down Expand Up @@ -59,18 +61,20 @@ type Pool struct {
Groups []string
AlpmExecutor db.Executor
Warnings *query.AURWarnings
aurClient *aur.Client
}

func makePool(dbExecutor db.Executor) *Pool {
func makePool(dbExecutor db.Executor, aurClient *aur.Client) *Pool {
dp := &Pool{
make([]Target, 0),
make(stringset.StringSet),
make(map[string]db.IPackage),
make(map[string]*query.Pkg),
make(map[string]*query.Pkg),
make([]string, 0),
dbExecutor,
nil,
Targets: []Target{},
Explicit: map[string]struct{}{},
Repo: map[string]alpm.IPackage{},
Aur: map[string]*aur.Pkg{},
AurCache: map[string]*aur.Pkg{},
Groups: []string{},
AlpmExecutor: dbExecutor,
Warnings: nil,
aurClient: aurClient,
}

return dp
Expand All @@ -81,8 +85,7 @@ func (dp *Pool) ResolveTargets(pkgs []string,
mode settings.TargetMode,
ignoreProviders, noConfirm, provides bool, rebuild string, splitN int, noDeps, noCheckDeps bool) error {
// RPC requests are slow
// Combine as many AUR package requests as possible into a single RPC
// call
// Combine as many AUR package requests as possible into a single RPC call
aurTargets := make(stringset.StringSet)

pkgs = query.RemoveInvalidTargets(pkgs, mode)
Expand Down Expand Up @@ -182,7 +185,7 @@ func (dp *Pool) findProvides(pkgs stringset.StringSet) error {
words := strings.Split(pkg, "-")

for i := range words {
results, err = query.Search(strings.Join(words[:i+1], "-"))
results, err = dp.aurClient.Search(context.Background(), strings.Join(words[:i+1], "-"), aur.None)
if err == nil {
break
}
Expand Down Expand Up @@ -246,7 +249,7 @@ func (dp *Pool) cacheAURPackages(_pkgs stringset.StringSet, provides bool, split
}
}

info, err := query.AURInfo(toQuery, dp.Warnings, splitN)
info, err := query.AURInfo(dp.aurClient, toQuery, dp.Warnings, splitN)
if err != nil {
return err
}
Expand Down Expand Up @@ -370,10 +373,11 @@ func (dp *Pool) ResolveRepoDependency(pkg db.IPackage, noDeps bool) {
func GetPool(pkgs []string,
warnings *query.AURWarnings,
dbExecutor db.Executor,
aurClient *aur.Client,
mode settings.TargetMode,
ignoreProviders, noConfirm, provides bool,
rebuild string, splitN int, noDeps bool, noCheckDeps bool) (*Pool, error) {
dp := makePool(dbExecutor)
dp := makePool(dbExecutor, aurClient)

dp.Warnings = warnings
err := dp.ResolveTargets(pkgs, mode, ignoreProviders, noConfirm, provides, rebuild, splitN, noDeps, noCheckDeps)
Expand Down
6 changes: 3 additions & 3 deletions pkg/pgp/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"strings"
"testing"

aur "github.com/Jguer/aur"
gosrc "github.com/Morganamilo/go-srcinfo"
"github.com/bradleyjkemp/cupaloy"
rpc "github.com/mikkeloscar/aur"

"github.com/Jguer/yay/v10/pkg/dep"
)
Expand All @@ -41,8 +41,8 @@ func init() {
})
}

func newPkg(basename string) *rpc.Pkg {
return &rpc.Pkg{Name: basename, PackageBase: basename}
func newPkg(basename string) *aur.Pkg {
return &aur.Pkg{Name: basename, PackageBase: basename}
}

func getPgpKey(key string) string {
Expand Down
22 changes: 9 additions & 13 deletions pkg/query/aur_info.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
package query

import (
"context"
"sync"

"github.com/Jguer/aur"
"github.com/leonelquinteros/gotext"
rpc "github.com/mikkeloscar/aur"

"github.com/Jguer/yay/v10/pkg/intrange"
"github.com/Jguer/yay/v10/pkg/multierror"
"github.com/Jguer/yay/v10/pkg/text"
)

type Pkg = rpc.Pkg

// Search is a reexport of rpc.Search
func Search(query string) ([]Pkg, error) {
return rpc.Search(query)
}
type Pkg = aur.Pkg

// Queries the aur for information about specified packages.
// All packages should be queried in a single rpc request except when the number
// 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 rpc requests will be
// If the number does exceed config.RequestSplitN multiple aur requests will be
// performed concurrently.
func AURInfo(names []string, warnings *AURWarnings, splitN int) ([]*Pkg, error) {
func AURInfo(aurClient *aur.Client, names []string, warnings *AURWarnings, splitN int) ([]*Pkg, error) {
info := make([]*Pkg, 0, len(names))
seen := make(map[string]int)
var mux sync.Mutex
Expand All @@ -32,7 +28,7 @@ func AURInfo(names []string, warnings *AURWarnings, splitN int) ([]*Pkg, error)

makeRequest := func(n, max int) {
defer wg.Done()
tempInfo, requestErr := rpc.Info(names[n:max])
tempInfo, requestErr := aurClient.Info(context.Background(), names[n:max])
errs.Add(requestErr)
if requestErr != nil {
return
Expand Down Expand Up @@ -80,11 +76,11 @@ func AURInfo(names []string, warnings *AURWarnings, splitN int) ([]*Pkg, error)
return info, nil
}

func AURInfoPrint(names []string, splitN int) ([]*Pkg, error) {
func AURInfoPrint(aurClient *aur.Client, names []string, splitN int) ([]*Pkg, error) {
text.OperationInfoln(gotext.Get("Querying AUR..."))

warnings := &AURWarnings{}
info, err := AURInfo(names, warnings, splitN)
info, err := AURInfo(aurClient, names, warnings, splitN)
if err != nil {
return info, err
}
Expand Down
Loading

0 comments on commit 545ea77

Please sign in to comment.