extract upgrade target adder

This commit is contained in:
jguer 2022-10-28 23:58:15 +02:00
parent 849e8f7b60
commit d3efb59da3
No known key found for this signature in database
GPG Key ID: 6D6CC9BEA8556B35
5 changed files with 46 additions and 24 deletions

View File

@ -125,18 +125,10 @@ func install(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Execu
// if we are doing -u also request all packages needing update
if sysupgradeArg {
ignore, targets, errUp := sysupgradeTargets(ctx, dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
if errUp != nil {
return errUp
}
for _, up := range targets {
cmdArgs.AddTarget(up)
requestTargets = append(requestTargets, up)
}
if len(ignore) > 0 {
arguments.CreateOrAppendOption("ignore", ignore.ToSlice()...)
var errSysUp error
requestTargets, errSysUp = addUpgradeTargetsToArgs(ctx, dbExecutor, cmdArgs, requestTargets, arguments)
if errSysUp != nil {
return errSysUp
}
}
@ -352,6 +344,23 @@ func install(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Execu
return nil
}
func addUpgradeTargetsToArgs(ctx context.Context, dbExecutor db.Executor, cmdArgs *parser.Arguments, requestTargets []string, arguments *parser.Arguments) ([]string, error) {
ignore, targets, errUp := sysupgradeTargets(ctx, dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
if errUp != nil {
return nil, errUp
}
for _, up := range targets {
cmdArgs.AddTarget(up)
requestTargets = append(requestTargets, up)
}
if len(ignore) > 0 {
arguments.CreateOrAppendOption("ignore", ignore.ToSlice()...)
}
return requestTargets, nil
}
func removeMake(ctx context.Context, cmdBuilder exe.ICmdBuilder, makeDeps []string) error {
removeArguments := parser.MakeArguments()

View File

@ -12,10 +12,12 @@ import (
"strings"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
"github.com/Jguer/aur"
"github.com/Jguer/votar/pkg/vote"
"github.com/Jguer/yay/v11/pkg/metadata"
"github.com/Jguer/yay/v11/pkg/settings/exe"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
@ -285,8 +287,14 @@ func NewConfig(version string) (*Configuration, error) {
QueryBuilder: nil,
}
var errAUR error
var errAURCache error
newConfig.Runtime.AURCache, errAURCache = metadata.NewAURCache(filepath.Join(newConfig.BuildDir, "aur.json"))
if errAURCache != nil {
return nil, errors.Wrap(errAURCache, gotext.Get("failed to retrieve aur Cache"))
}
var errAUR error
newConfig.Runtime.AURClient, errAUR = aur.NewClient(aur.WithHTTPClient(newConfig.Runtime.HTTPClient),
aur.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
req.Header.Set("User-Agent", userAgent)

View File

@ -8,6 +8,7 @@ import (
"github.com/Jguer/aur"
"github.com/Jguer/votar/pkg/vote"
"github.com/Jguer/yay/v11/pkg/metadata"
"github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/settings/exe"
"github.com/Jguer/yay/v11/pkg/settings/parser"
@ -27,4 +28,5 @@ type Runtime struct {
HTTPClient *http.Client
AURClient *aur.Client
VoteClient *vote.Client
AURCache *metadata.AURCache
}

19
sync.go
View File

@ -3,25 +3,28 @@ package main
import (
"context"
"os"
"path/filepath"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/metadata"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
)
func syncInstall(ctx context.Context,
config *settings.Configuration,
cmdArgs *parser.Arguments, dbExecutor db.Executor,
cmdArgs *parser.Arguments,
dbExecutor db.Executor,
) error {
aurCache, err := metadata.NewAURCache(filepath.Join(config.BuildDir, "aur.json"))
if err != nil {
return errors.Wrap(err, gotext.Get("failed to retrieve aur Cache"))
aurCache := config.Runtime.AURCache
if cmdArgs.ExistsArg("u", "sysupgrade") {
var errSysUp error
// All of the installs are done as explicit installs, this should be move to a grapher method
_, errSysUp = addUpgradeTargetsToArgs(ctx, dbExecutor, cmdArgs, []string{}, cmdArgs)
if errSysUp != nil {
return errSysUp
}
}
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)

View File

@ -171,7 +171,7 @@ func upgradePkgsMenu(aurUp, repoUp upgrade.UpSlice) (stringset.StringSet, []stri
if !config.UpgradeMenu {
for _, pkg := range aurUp.Up {
targets = append(targets, pkg.Name)
targets = append(targets, pkg.Repository+"/"+pkg.Name)
}
return ignore, targets, nil
@ -204,12 +204,12 @@ func upgradePkgsMenu(aurUp, repoUp upgrade.UpSlice) (stringset.StringSet, []stri
}
if isInclude && !include.Get(len(repoUp.Up)-i+len(aurUp.Up)) {
targets = append(targets, pkg.Name)
targets = append(targets, pkg.Repository+"/"+pkg.Name)
continue
}
if !isInclude && (exclude.Get(len(repoUp.Up)-i+len(aurUp.Up)) || otherExclude.Get(pkg.Repository)) {
targets = append(targets, pkg.Name)
targets = append(targets, pkg.Repository+"/"+pkg.Name)
continue
}