mirror of
https://github.com/Jguer/yay.git
synced 2025-10-08 00:04:37 -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")
|
assumeInstalled = cmdArgs.GetArgs("assume-installed")
|
||||||
sysupgradeArg = cmdArgs.ExistsArg("u", "sysupgrade")
|
sysupgradeArg = cmdArgs.ExistsArg("u", "sysupgrade")
|
||||||
refreshArg = cmdArgs.ExistsArg("y", "refresh")
|
refreshArg = cmdArgs.ExistsArg("y", "refresh")
|
||||||
warnings = query.NewWarnings()
|
warnings = query.NewWarnings(cfg.Runtime.Logger)
|
||||||
)
|
)
|
||||||
|
|
||||||
if noDeps {
|
if noDeps {
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package query
|
package query
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"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/stringset"
|
||||||
"github.com/Jguer/yay/v12/pkg/text"
|
"github.com/Jguer/yay/v12/pkg/text"
|
||||||
)
|
)
|
||||||
@ -15,33 +17,58 @@ type AURWarnings struct {
|
|||||||
OutOfDate []string
|
OutOfDate []string
|
||||||
Missing []string
|
Missing []string
|
||||||
Ignore stringset.StringSet
|
Ignore stringset.StringSet
|
||||||
|
|
||||||
|
log *text.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWarnings() *AURWarnings {
|
func NewWarnings(logger *text.Logger) *AURWarnings {
|
||||||
return &AURWarnings{Ignore: make(stringset.StringSet)}
|
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() {
|
func (warnings *AURWarnings) Print() {
|
||||||
normalMissing, debugMissing := filterDebugPkgs(warnings.Missing)
|
normalMissing, debugMissing := filterDebugPkgs(warnings.Missing)
|
||||||
|
|
||||||
if len(normalMissing) > 0 {
|
if len(normalMissing) > 0 {
|
||||||
text.Warn(gotext.Get("Packages not in AUR:"))
|
warnings.log.Warnln(gotext.Get("Packages not in AUR:"), formatNames(normalMissing))
|
||||||
printRange(normalMissing)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(debugMissing) > 0 {
|
if len(debugMissing) > 0 {
|
||||||
text.Warn(gotext.Get("Missing AUR Debug Packages:"))
|
warnings.log.Warnln(gotext.Get("Missing AUR Debug Packages:"), formatNames(debugMissing))
|
||||||
printRange(debugMissing)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(warnings.Orphans) > 0 {
|
if len(warnings.Orphans) > 0 {
|
||||||
text.Warn(gotext.Get("Orphan (unmaintained) AUR Packages:"))
|
warnings.log.Warnln(gotext.Get("Orphan (unmaintained) AUR Packages:"), formatNames(warnings.Orphans))
|
||||||
printRange(warnings.Orphans)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(warnings.OutOfDate) > 0 {
|
if len(warnings.OutOfDate) > 0 {
|
||||||
text.Warn(gotext.Get("Flagged Out Of Date AUR Packages:"))
|
warnings.log.Warnln(gotext.Get("Flagged Out Of Date AUR Packages:"), formatNames(warnings.OutOfDate))
|
||||||
printRange(warnings.OutOfDate)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,10 +87,6 @@ func filterDebugPkgs(names []string) (normal, debug []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func printRange(names []string) {
|
func formatNames(names []string) string {
|
||||||
for _, name := range names {
|
return " " + text.Cyan(strings.Join(names, " "))
|
||||||
fmt.Print(" " + text.Cyan(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println()
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/Jguer/yay/v12/pkg/dep"
|
"github.com/Jguer/yay/v12/pkg/dep"
|
||||||
"github.com/Jguer/yay/v12/pkg/intrange"
|
"github.com/Jguer/yay/v12/pkg/intrange"
|
||||||
"github.com/Jguer/yay/v12/pkg/multierror"
|
"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/settings"
|
||||||
"github.com/Jguer/yay/v12/pkg/text"
|
"github.com/Jguer/yay/v12/pkg/text"
|
||||||
"github.com/Jguer/yay/v12/pkg/topo"
|
"github.com/Jguer/yay/v12/pkg/topo"
|
||||||
@ -27,6 +28,8 @@ type UpgradeService struct {
|
|||||||
cfg *settings.Configuration
|
cfg *settings.Configuration
|
||||||
log *text.Logger
|
log *text.Logger
|
||||||
noConfirm bool
|
noConfirm bool
|
||||||
|
|
||||||
|
AURWarnings *query.AURWarnings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUpgradeService(grapher *dep.Grapher, aurCache aur.QueryClient,
|
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,
|
cfg *settings.Configuration, noConfirm bool, logger *text.Logger,
|
||||||
) *UpgradeService {
|
) *UpgradeService {
|
||||||
return &UpgradeService{
|
return &UpgradeService{
|
||||||
grapher: grapher,
|
grapher: grapher,
|
||||||
aurCache: aurCache,
|
aurCache: aurCache,
|
||||||
dbExecutor: dbExecutor,
|
dbExecutor: dbExecutor,
|
||||||
vcsStore: vcsStore,
|
vcsStore: vcsStore,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
noConfirm: noConfirm,
|
noConfirm: noConfirm,
|
||||||
log: logger,
|
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 {
|
for i := range _aurdata {
|
||||||
pkg := &_aurdata[i]
|
pkg := &_aurdata[i]
|
||||||
aurdata[pkg.Name] = pkg
|
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)
|
aurUp = UpAUR(u.log, remote, aurdata, u.cfg.TimeUpdate, enableDowngrade)
|
||||||
|
|
||||||
if u.cfg.Devel {
|
if u.cfg.Devel {
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/Jguer/yay/v12/pkg/db"
|
"github.com/Jguer/yay/v12/pkg/db"
|
||||||
"github.com/Jguer/yay/v12/pkg/db/mock"
|
"github.com/Jguer/yay/v12/pkg/db/mock"
|
||||||
"github.com/Jguer/yay/v12/pkg/dep"
|
"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"
|
||||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v12/pkg/text"
|
"github.com/Jguer/yay/v12/pkg/text"
|
||||||
@ -341,15 +342,17 @@ func TestUpgradeService_GraphUpgrades(t *testing.T) {
|
|||||||
Devel: tt.fields.devel, Mode: parser.ModeAny,
|
Devel: tt.fields.devel, Mode: parser.ModeAny,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger := text.NewLogger(tt.fields.output,
|
||||||
|
tt.fields.input, true, "test")
|
||||||
u := &UpgradeService{
|
u := &UpgradeService{
|
||||||
log: text.NewLogger(tt.fields.output,
|
log: logger,
|
||||||
tt.fields.input, true, "test"),
|
grapher: grapher,
|
||||||
grapher: grapher,
|
aurCache: mockAUR,
|
||||||
aurCache: mockAUR,
|
dbExecutor: dbExe,
|
||||||
dbExecutor: dbExe,
|
vcsStore: vcsStore,
|
||||||
vcsStore: vcsStore,
|
cfg: cfg,
|
||||||
cfg: cfg,
|
noConfirm: tt.fields.noConfirm,
|
||||||
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 })
|
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,
|
Mode: parser.ModeAny,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger := text.NewLogger(tt.fields.output,
|
||||||
|
tt.fields.input, true, "test")
|
||||||
u := &UpgradeService{
|
u := &UpgradeService{
|
||||||
log: text.NewLogger(tt.fields.output,
|
log: logger,
|
||||||
tt.fields.input, true, "test"),
|
grapher: grapher,
|
||||||
grapher: grapher,
|
aurCache: mockAUR,
|
||||||
aurCache: mockAUR,
|
dbExecutor: dbExe,
|
||||||
dbExecutor: dbExe,
|
vcsStore: vcsStore,
|
||||||
vcsStore: vcsStore,
|
cfg: cfg,
|
||||||
cfg: cfg,
|
noConfirm: tt.fields.noConfirm,
|
||||||
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 })
|
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 {
|
if errSysUp != nil {
|
||||||
return errSysUp
|
return errSysUp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upService.AURWarnings.Print()
|
||||||
|
|
||||||
excluded, errSysUp = upService.UserExcludeUpgrades(graph)
|
excluded, errSysUp = upService.UserExcludeUpgrades(graph)
|
||||||
if errSysUp != nil {
|
if errSysUp != nil {
|
||||||
return errSysUp
|
return errSysUp
|
||||||
|
@ -632,6 +632,7 @@ func TestSyncUpgrade_NoCombinedUpgrade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
makepkgBin := t.TempDir() + "/makepkg"
|
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,
|
func sysupgradeTargets(ctx context.Context, cfg *settings.Configuration, dbExecutor db.Executor,
|
||||||
enableDowngrade bool,
|
enableDowngrade bool,
|
||||||
) (stringset.StringSet, []string, error) {
|
) (stringset.StringSet, []string, error) {
|
||||||
warnings := query.NewWarnings()
|
warnings := query.NewWarnings(cfg.Runtime.Logger)
|
||||||
|
|
||||||
aurUp, repoUp, err := upList(ctx, cfg, warnings, dbExecutor, enableDowngrade,
|
aurUp, repoUp, err := upList(ctx, cfg, warnings, dbExecutor, enableDowngrade,
|
||||||
func(*upgrade.Upgrade) bool { return true })
|
func(*upgrade.Upgrade) bool { return true })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user