add basic sync upgrade capabilities

This commit is contained in:
jguer 2022-11-01 23:48:35 +01:00
parent 776fc9686a
commit b5bdcfbd1a
No known key found for this signature in database
GPG Key ID: 6D6CC9BEA8556B35
8 changed files with 163 additions and 32 deletions

View File

@ -200,7 +200,7 @@ func (installer *Installer) getNewTargets(pkgdests map[string]string, name strin
pkgArchives := make([]string, 0, 2)
if _, errStat := os.Stat(pkgdest); os.IsNotExist(errStat) {
return nil, false, &UnableToFindPkgDestError{name: name, pkgDest: pkgdest}
return nil, false, &FindPkgDestError{name: name, pkgDest: pkgdest}
}
pkgArchives = append(pkgArchives, pkgdest)
@ -229,6 +229,7 @@ func (*Installer) installSyncPackages(ctx context.Context, cmdArgs *parser.Argum
arguments.DelArg("asdeps", "asdep")
arguments.DelArg("asexplicit", "asexp")
arguments.DelArg("i", "install")
arguments.DelArg("u", "upgrade")
arguments.Op = "S"
arguments.ClearTargets()
arguments.AddTarget(repoTargets...)

View File

@ -2,11 +2,24 @@ package main
import "github.com/leonelquinteros/gotext"
type UnableToFindPkgDestError struct {
type SetPkgReasonError struct {
exp bool // explicit
}
func (e *SetPkgReasonError) Error() string {
reason := gotext.Get("explicit")
if !e.exp {
reason = gotext.Get("dependency")
}
return gotext.Get("error updating package install reason to %s", reason)
}
type FindPkgDestError struct {
name, pkgDest string
}
func (e *UnableToFindPkgDestError) Error() string {
func (e *FindPkgDestError) Error() string {
return gotext.Get(
"the PKGDEST for %s is listed by makepkg but does not exist: %s",
e.name, e.pkgDest)

View File

@ -28,40 +28,47 @@ import (
"github.com/Jguer/yay/v11/pkg/text"
)
func asdeps(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) error {
func setPkgReason(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string, exp bool) error {
if len(pkgs) == 0 {
return nil
}
cmdArgs = cmdArgs.CopyGlobal()
_ = cmdArgs.AddArg("q", "D", "asdeps")
cmdArgs.AddTarget(pkgs...)
if exp {
if err := cmdArgs.AddArg("q", "D", "asexplicit"); err != nil {
return err
}
} else {
if err := cmdArgs.AddArg("q", "D", "asdeps"); err != nil {
return err
}
}
for _, compositePkgName := range pkgs {
pkgSplit := strings.Split(compositePkgName, "/")
pkgName := pkgSplit[0]
if len(pkgSplit) > 1 {
pkgName = pkgSplit[1]
}
cmdArgs.AddTarget(pkgName)
}
err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
if err != nil {
return errors.New(gotext.Get("error updating package install reason to dependency"))
return &SetPkgReasonError{exp: exp}
}
return nil
}
func asdeps(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) error {
return setPkgReason(ctx, cmdArgs, pkgs, false)
}
func asexp(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) error {
if len(pkgs) == 0 {
return nil
}
cmdArgs = cmdArgs.CopyGlobal()
_ = cmdArgs.AddArg("q", "D", "asexplicit")
cmdArgs.AddTarget(pkgs...)
err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
if err != nil {
return fmt.Errorf("%s - %w", gotext.Get("error updating package install reason to explicit"), err)
}
return nil
return setPkgReason(ctx, cmdArgs, pkgs, true)
}
// Install handles package installs.

View File

@ -19,6 +19,7 @@ func VerCmp(v1, v2 string) int {
type Upgrade struct {
Name string
Base string
Repository string
LocalVersion string
RemoteVersion string

View File

@ -427,6 +427,7 @@ func (ae *AlpmExecutor) RepoUpgrades(enableDowngrade bool) ([]db.Upgrade, error)
slice = append(slice, upgrade.Upgrade{
Name: pkg.Name(),
Base: pkg.Base(),
Repository: pkg.DB().Name(),
LocalVersion: localVer,
RemoteVersion: pkg.Version(),

View File

@ -16,7 +16,8 @@ func UpDevel(
ctx context.Context,
remote []db.IPackage,
aurdata map[string]*query.Pkg,
localCache *vcs.InfoStore) UpSlice {
localCache *vcs.InfoStore,
) UpSlice {
toUpdate := make([]db.IPackage, 0, len(aurdata))
toRemove := make([]string, 0)
@ -64,9 +65,11 @@ func UpDevel(
toUpgrade.Up = append(toUpgrade.Up,
Upgrade{
Name: pkg.Name(),
Base: pkg.Base(),
Repository: "devel",
LocalVersion: pkg.Version(),
RemoteVersion: "latest-commit",
Reason: pkg.Reason(),
})
}
}
@ -104,6 +107,7 @@ func UpAUR(remote []db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool)
toUpgrade.Up = append(toUpgrade.Up,
Upgrade{
Name: aurPkg.Name,
Base: aurPkg.PackageBase,
Repository: "aur",
LocalVersion: pkg.Version(),
RemoteVersion: aurPkg.Version,

17
sync.go
View File

@ -18,15 +18,6 @@ func syncInstall(ctx context.Context,
) error {
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)
graph, err := grapher.GraphFromTargets(cmdArgs.Targets)
@ -34,6 +25,14 @@ func syncInstall(ctx context.Context,
return err
}
if cmdArgs.ExistsArg("u", "sysupgrade") {
var errSysUp error
graph, _, errSysUp = sysupgradeTargetsV2(ctx, dbExecutor, graph, cmdArgs.ExistsDouble("u", "sysupgrade"))
if errSysUp != nil {
return errSysUp
}
}
topoSorted := graph.TopoSortedLayerMap()
preparer := &Preparer{

View File

@ -12,12 +12,14 @@ import (
"github.com/leonelquinteros/gotext"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/intrange"
"github.com/Jguer/yay/v11/pkg/multierror"
"github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/stringset"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/topo"
"github.com/Jguer/yay/v11/pkg/upgrade"
)
@ -249,3 +251,106 @@ func sysupgradeTargets(ctx context.Context, dbExecutor db.Executor,
return upgradePkgsMenu(aurUp, repoUp)
}
// Targets for sys upgrade.
func sysupgradeTargetsV2(ctx context.Context,
dbExecutor db.Executor,
graph *topo.Graph[string, *dep.InstallInfo],
enableDowngrade bool,
) (*topo.Graph[string, *dep.InstallInfo], stringset.StringSet, error) {
warnings := query.NewWarnings()
aurUp, repoUp, err := upList(ctx, warnings, dbExecutor, enableDowngrade,
func(upgrade.Upgrade) bool { return true })
if err != nil {
return graph, nil, err
}
warnings.Print()
ignore := make(stringset.StringSet)
allUpLen := len(repoUp.Up) + len(aurUp.Up)
if allUpLen == 0 {
return graph, ignore, nil
}
sort.Sort(repoUp)
sort.Sort(aurUp)
allUp := upgrade.UpSlice{Up: append(repoUp.Up, aurUp.Up...), Repos: append(repoUp.Repos, aurUp.Repos...)}
fmt.Printf("%s"+text.Bold(" %d ")+"%s\n", text.Bold(text.Cyan("::")), allUpLen, text.Bold(gotext.Get("Packages to upgrade.")))
allUp.Print()
text.Infoln(gotext.Get("Packages to exclude: (eg: \"1 2 3\", \"1-3\", \"^4\" or repo name)"))
numbers, err := text.GetInput(config.AnswerUpgrade, settings.NoConfirm)
if err != nil {
return nil, nil, err
}
// upgrade menu asks you which packages to NOT upgrade so in this case
// include and exclude are kind of swapped
include, exclude, otherInclude, otherExclude := intrange.ParseNumberMenu(numbers)
isInclude := len(exclude) == 0 && len(otherExclude) == 0
for i, pkg := range repoUp.Up {
if isInclude && otherInclude.Get(pkg.Repository) {
ignore.Set(pkg.Name)
}
if isInclude && !include.Get(len(repoUp.Up)-i+len(aurUp.Up)) {
addUpgradeToGraph(pkg, graph)
continue
}
if !isInclude && (exclude.Get(len(repoUp.Up)-i+len(aurUp.Up)) || otherExclude.Get(pkg.Repository)) {
addUpgradeToGraph(pkg, graph)
continue
}
ignore.Set(pkg.Name)
}
for i, pkg := range aurUp.Up {
if isInclude && otherInclude.Get(pkg.Repository) {
continue
}
if isInclude && !include.Get(len(aurUp.Up)-i) {
addUpgradeToGraph(pkg, graph)
}
if !isInclude && (exclude.Get(len(aurUp.Up)-i) || otherExclude.Get(pkg.Repository)) {
addUpgradeToGraph(pkg, graph)
}
}
return graph, ignore, err
}
func addUpgradeToGraph(pkg db.Upgrade, graph *topo.Graph[string, *dep.InstallInfo]) {
source := dep.Sync
if pkg.Repository == "aur" {
source = dep.AUR
}
reason := dep.Explicit
if pkg.Reason == alpm.PkgReasonDepend {
reason = dep.Dep
}
graph.AddNode(pkg.Name)
graph.SetNodeInfo(pkg.Name, &topo.NodeInfo[*dep.InstallInfo]{
Color: "",
Background: "",
Value: &dep.InstallInfo{
Source: source,
Reason: reason,
Version: pkg.RemoteVersion,
AURBase: &pkg.Base,
SyncDBName: &pkg.Repository,
},
})
}