mirror of
https://github.com/Jguer/yay.git
synced 2025-10-07 00:14:22 -04:00
fix(new_engine): add missing warnings to AUR updates (#2087)
* add missing warnings to AUR updates * fix tests
This commit is contained in:
parent
a64180464b
commit
1ee94f28d3
@ -96,7 +96,7 @@ func install(ctx context.Context, cfg *settings.Configuration,
|
||||
assumeInstalled = cmdArgs.GetArgs("assume-installed")
|
||||
sysupgradeArg = cmdArgs.ExistsArg("u", "sysupgrade")
|
||||
refreshArg = cmdArgs.ExistsArg("y", "refresh")
|
||||
warnings = query.NewWarnings()
|
||||
warnings = query.NewWarnings(cfg.Runtime.Logger)
|
||||
)
|
||||
|
||||
if noDeps {
|
||||
|
@ -1,11 +1,13 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
@ -15,33 +17,58 @@ type AURWarnings struct {
|
||||
OutOfDate []string
|
||||
Missing []string
|
||||
Ignore stringset.StringSet
|
||||
|
||||
log *text.Logger
|
||||
}
|
||||
|
||||
func NewWarnings() *AURWarnings {
|
||||
return &AURWarnings{Ignore: make(stringset.StringSet)}
|
||||
func NewWarnings(logger *text.Logger) *AURWarnings {
|
||||
if logger == nil {
|
||||
logger = text.GlobalLogger
|
||||
}
|
||||
return &AURWarnings{Ignore: make(stringset.StringSet), log: logger}
|
||||
}
|
||||
|
||||
func (warnings *AURWarnings) AddToWarnings(remote map[string]alpm.IPackage, aurPkg *aur.Pkg) {
|
||||
name := aurPkg.Name
|
||||
pkg, ok := remote[name]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if aurPkg.Maintainer == "" && !pkg.ShouldIgnore() {
|
||||
warnings.Orphans = append(warnings.Orphans, name)
|
||||
}
|
||||
|
||||
if aurPkg.OutOfDate != 0 && !pkg.ShouldIgnore() {
|
||||
warnings.OutOfDate = append(warnings.OutOfDate, name)
|
||||
}
|
||||
}
|
||||
|
||||
func (warnings *AURWarnings) CalculateMissing(remoteNames []string, remote map[string]alpm.IPackage, aurData map[string]*aur.Pkg) {
|
||||
for _, name := range remoteNames {
|
||||
if _, ok := aurData[name]; !ok && !remote[name].ShouldIgnore() {
|
||||
warnings.Missing = append(warnings.Missing, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (warnings *AURWarnings) Print() {
|
||||
normalMissing, debugMissing := filterDebugPkgs(warnings.Missing)
|
||||
|
||||
if len(normalMissing) > 0 {
|
||||
text.Warn(gotext.Get("Packages not in AUR:"))
|
||||
printRange(normalMissing)
|
||||
warnings.log.Warnln(gotext.Get("Packages not in AUR:"), formatNames(normalMissing))
|
||||
}
|
||||
|
||||
if len(debugMissing) > 0 {
|
||||
text.Warn(gotext.Get("Missing AUR Debug Packages:"))
|
||||
printRange(debugMissing)
|
||||
warnings.log.Warnln(gotext.Get("Missing AUR Debug Packages:"), formatNames(debugMissing))
|
||||
}
|
||||
|
||||
if len(warnings.Orphans) > 0 {
|
||||
text.Warn(gotext.Get("Orphan (unmaintained) AUR Packages:"))
|
||||
printRange(warnings.Orphans)
|
||||
warnings.log.Warnln(gotext.Get("Orphan (unmaintained) AUR Packages:"), formatNames(warnings.Orphans))
|
||||
}
|
||||
|
||||
if len(warnings.OutOfDate) > 0 {
|
||||
text.Warn(gotext.Get("Flagged Out Of Date AUR Packages:"))
|
||||
printRange(warnings.OutOfDate)
|
||||
warnings.log.Warnln(gotext.Get("Flagged Out Of Date AUR Packages:"), formatNames(warnings.OutOfDate))
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,10 +87,6 @@ func filterDebugPkgs(names []string) (normal, debug []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func printRange(names []string) {
|
||||
for _, name := range names {
|
||||
fmt.Print(" " + text.Cyan(name))
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
func formatNames(names []string) string {
|
||||
return " " + text.Cyan(strings.Join(names, " "))
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/Jguer/yay/v12/pkg/dep"
|
||||
"github.com/Jguer/yay/v12/pkg/intrange"
|
||||
"github.com/Jguer/yay/v12/pkg/multierror"
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
"github.com/Jguer/yay/v12/pkg/topo"
|
||||
@ -27,6 +28,8 @@ type UpgradeService struct {
|
||||
cfg *settings.Configuration
|
||||
log *text.Logger
|
||||
noConfirm bool
|
||||
|
||||
AURWarnings *query.AURWarnings
|
||||
}
|
||||
|
||||
func NewUpgradeService(grapher *dep.Grapher, aurCache aur.QueryClient,
|
||||
@ -34,13 +37,14 @@ func NewUpgradeService(grapher *dep.Grapher, aurCache aur.QueryClient,
|
||||
cfg *settings.Configuration, noConfirm bool, logger *text.Logger,
|
||||
) *UpgradeService {
|
||||
return &UpgradeService{
|
||||
grapher: grapher,
|
||||
aurCache: aurCache,
|
||||
dbExecutor: dbExecutor,
|
||||
vcsStore: vcsStore,
|
||||
cfg: cfg,
|
||||
noConfirm: noConfirm,
|
||||
log: logger,
|
||||
grapher: grapher,
|
||||
aurCache: aurCache,
|
||||
dbExecutor: dbExecutor,
|
||||
vcsStore: vcsStore,
|
||||
cfg: cfg,
|
||||
noConfirm: noConfirm,
|
||||
log: logger,
|
||||
AURWarnings: query.NewWarnings(logger.Child("warnings")),
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,8 +74,11 @@ func (u *UpgradeService) upGraph(ctx context.Context, graph *topo.Graph[string,
|
||||
for i := range _aurdata {
|
||||
pkg := &_aurdata[i]
|
||||
aurdata[pkg.Name] = pkg
|
||||
u.AURWarnings.AddToWarnings(remote, pkg)
|
||||
}
|
||||
|
||||
u.AURWarnings.CalculateMissing(remoteNames, remote, aurdata)
|
||||
|
||||
aurUp = UpAUR(u.log, remote, aurdata, u.cfg.TimeUpdate, enableDowngrade)
|
||||
|
||||
if u.cfg.Devel {
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/db/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/dep"
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
@ -341,15 +342,17 @@ func TestUpgradeService_GraphUpgrades(t *testing.T) {
|
||||
Devel: tt.fields.devel, Mode: parser.ModeAny,
|
||||
}
|
||||
|
||||
logger := text.NewLogger(tt.fields.output,
|
||||
tt.fields.input, true, "test")
|
||||
u := &UpgradeService{
|
||||
log: text.NewLogger(tt.fields.output,
|
||||
tt.fields.input, true, "test"),
|
||||
grapher: grapher,
|
||||
aurCache: mockAUR,
|
||||
dbExecutor: dbExe,
|
||||
vcsStore: vcsStore,
|
||||
cfg: cfg,
|
||||
noConfirm: tt.fields.noConfirm,
|
||||
log: logger,
|
||||
grapher: grapher,
|
||||
aurCache: mockAUR,
|
||||
dbExecutor: dbExe,
|
||||
vcsStore: vcsStore,
|
||||
cfg: cfg,
|
||||
noConfirm: tt.fields.noConfirm,
|
||||
AURWarnings: query.NewWarnings(logger),
|
||||
}
|
||||
|
||||
got, err := u.GraphUpgrades(context.Background(), tt.args.graph, tt.args.enableDowngrade, func(*Upgrade) bool { return true })
|
||||
@ -461,15 +464,17 @@ func TestUpgradeService_GraphUpgradesNoUpdates(t *testing.T) {
|
||||
Mode: parser.ModeAny,
|
||||
}
|
||||
|
||||
logger := text.NewLogger(tt.fields.output,
|
||||
tt.fields.input, true, "test")
|
||||
u := &UpgradeService{
|
||||
log: text.NewLogger(tt.fields.output,
|
||||
tt.fields.input, true, "test"),
|
||||
grapher: grapher,
|
||||
aurCache: mockAUR,
|
||||
dbExecutor: dbExe,
|
||||
vcsStore: vcsStore,
|
||||
cfg: cfg,
|
||||
noConfirm: tt.fields.noConfirm,
|
||||
log: logger,
|
||||
grapher: grapher,
|
||||
aurCache: mockAUR,
|
||||
dbExecutor: dbExe,
|
||||
vcsStore: vcsStore,
|
||||
cfg: cfg,
|
||||
noConfirm: tt.fields.noConfirm,
|
||||
AURWarnings: query.NewWarnings(logger),
|
||||
}
|
||||
|
||||
got, err := u.GraphUpgrades(context.Background(), tt.args.graph, tt.args.enableDowngrade, func(*Upgrade) bool { return true })
|
||||
@ -494,3 +499,99 @@ func TestUpgradeService_GraphUpgradesNoUpdates(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpgradeService_Warnings(t *testing.T) {
|
||||
t.Parallel()
|
||||
dbExe := &mock.DBExecutor{
|
||||
InstalledRemotePackageNamesFn: func() []string {
|
||||
return []string{"orphan", "outdated", "missing", "orphan-ignored"}
|
||||
},
|
||||
InstalledRemotePackagesFn: func() map[string]mock.IPackage {
|
||||
mapRemote := make(map[string]mock.IPackage)
|
||||
mapRemote["orphan"] = &mock.Package{
|
||||
PName: "orphan",
|
||||
PBase: "orphan",
|
||||
PVersion: "10.2.3",
|
||||
PReason: alpm.PkgReasonExplicit,
|
||||
}
|
||||
|
||||
mapRemote["outdated"] = &mock.Package{
|
||||
PName: "outdated",
|
||||
PBase: "outdated",
|
||||
PVersion: "10.2.3",
|
||||
PReason: alpm.PkgReasonExplicit,
|
||||
}
|
||||
|
||||
mapRemote["missing"] = &mock.Package{
|
||||
PName: "missing",
|
||||
PBase: "missing",
|
||||
PVersion: "10.2.3",
|
||||
PReason: alpm.PkgReasonExplicit,
|
||||
}
|
||||
|
||||
mapRemote["orphan-ignored"] = &mock.Package{
|
||||
PName: "orphan-ignored",
|
||||
PBase: "orphan-ignored",
|
||||
PVersion: "10.2.3",
|
||||
PReason: alpm.PkgReasonExplicit,
|
||||
PShouldIgnore: true,
|
||||
}
|
||||
|
||||
return mapRemote
|
||||
},
|
||||
LocalSatisfierExistsFn: func(string) bool { return false },
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
return nil
|
||||
},
|
||||
SyncUpgradesFn: func(bool) (map[string]db.SyncUpgrade, error) {
|
||||
mapUpgrades := make(map[string]db.SyncUpgrade)
|
||||
return mapUpgrades, nil
|
||||
},
|
||||
ReposFn: func() []string { return []string{"core"} },
|
||||
}
|
||||
vcsStore := &vcs.Mock{
|
||||
ToUpgradeReturn: []string{},
|
||||
}
|
||||
|
||||
mockAUR := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{
|
||||
{
|
||||
Name: "outdated", Version: "10.2.4", PackageBase: "orphan",
|
||||
OutOfDate: 100, Maintainer: "bob",
|
||||
},
|
||||
{
|
||||
Name: "orphan", Version: "10.2.4", PackageBase: "orphan",
|
||||
Maintainer: "",
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
|
||||
logger := text.NewLogger(io.Discard,
|
||||
strings.NewReader("\n"), true, "test")
|
||||
grapher := dep.NewGrapher(dbExe, mockAUR,
|
||||
false, true, false, false, false, logger)
|
||||
|
||||
cfg := &settings.Configuration{
|
||||
Devel: false, Mode: parser.ModeAUR,
|
||||
}
|
||||
|
||||
u := &UpgradeService{
|
||||
log: logger,
|
||||
grapher: grapher,
|
||||
aurCache: mockAUR,
|
||||
dbExecutor: dbExe,
|
||||
vcsStore: vcsStore,
|
||||
cfg: cfg,
|
||||
noConfirm: true,
|
||||
AURWarnings: query.NewWarnings(logger),
|
||||
}
|
||||
|
||||
_, err := u.GraphUpgrades(context.Background(), nil, false, func(*Upgrade) bool { return true })
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []string{"missing"}, u.AURWarnings.Missing)
|
||||
assert.Equal(t, []string{"outdated"}, u.AURWarnings.OutOfDate)
|
||||
assert.Equal(t, []string{"orphan"}, u.AURWarnings.Orphans)
|
||||
}
|
||||
|
3
sync.go
3
sync.go
@ -66,6 +66,9 @@ func syncInstall(ctx context.Context,
|
||||
if errSysUp != nil {
|
||||
return errSysUp
|
||||
}
|
||||
|
||||
upService.AURWarnings.Print()
|
||||
|
||||
excluded, errSysUp = upService.UserExcludeUpgrades(graph)
|
||||
if errSysUp != nil {
|
||||
return errSysUp
|
||||
|
@ -632,6 +632,7 @@ func TestSyncUpgrade_NoCombinedUpgrade(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
|
@ -262,7 +262,7 @@ func upgradePkgsMenu(cfg *settings.Configuration, aurUp, repoUp upgrade.UpSlice)
|
||||
func sysupgradeTargets(ctx context.Context, cfg *settings.Configuration, dbExecutor db.Executor,
|
||||
enableDowngrade bool,
|
||||
) (stringset.StringSet, []string, error) {
|
||||
warnings := query.NewWarnings()
|
||||
warnings := query.NewWarnings(cfg.Runtime.Logger)
|
||||
|
||||
aurUp, repoUp, err := upList(ctx, cfg, warnings, dbExecutor, enableDowngrade,
|
||||
func(*upgrade.Upgrade) bool { return true })
|
||||
|
Loading…
x
Reference in New Issue
Block a user