Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ func handleSync(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Argum
case cmdArgs.ExistsArg("s", "search"):
return syncSearch(ctx, targets, dbExecutor, run.QueryBuilder, !cmdArgs.ExistsArg("q", "quiet"))
case cmdArgs.ExistsArg("p", "print", "print-format"):
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
return syncPrint(ctx, run, cmdArgs, dbExecutor)
case cmdArgs.ExistsArg("c", "clean"):
return syncClean(ctx, run, cmdArgs, dbExecutor)
case cmdArgs.ExistsArg("l", "list"):
Expand Down
3 changes: 3 additions & 0 deletions pkg/settings/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (c *Configuration) handleOption(option, value string) bool {
c.SortBy = value
case "searchby":
c.SearchBy = value
case "print-format":
c.PrintFormat = value
return false
case "noconfirm":
NoConfirm = boolValue
case "config":
Expand Down
8 changes: 5 additions & 3 deletions pkg/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ type Configuration struct {
CompletionPath string `json:"-"`
VCSFilePath string `json:"-"`
// ConfigPath string `json:"-"`
SaveConfig bool `json:"-"`
Mode parser.TargetMode `json:"-"`
ReBuild parser.RebuildMode `json:"rebuild"`
SaveConfig bool `json:"-"`
Mode parser.TargetMode `json:"-"`
ReBuild parser.RebuildMode `json:"rebuild"`
PrintFormat string `json:"-"`
}

// SaveConfig writes yay config to file.
Expand Down Expand Up @@ -238,6 +239,7 @@ func DefaultConfig(version string) *Configuration {
UseRPC: true,
DoubleConfirm: true,
Mode: parser.ModeAny,
PrintFormat: "%l",
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/settings/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func (a *Arguments) NeedRoot(mode TargetMode) bool {

return true
case "U", "upgrade":
if a.ExistsArg("p", "print", "print-format") {
return false
}

return true
default:
return false
Expand Down
76 changes: 42 additions & 34 deletions pkg/upgrade/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,42 +57,11 @@ func (u *UpgradeService) upGraph(ctx context.Context, graph *topo.Graph[string,
enableDowngrade bool,
filter Filter,
) (err error) {
var (
develUp UpSlice
errs multierror.MultiError
aurdata = make(map[string]*aur.Pkg)
aurUp UpSlice
)

remote := u.dbExecutor.InstalledRemotePackages()
remoteNames := u.dbExecutor.InstalledRemotePackageNames()

if u.cfg.Mode.AtLeastAUR() {
u.log.OperationInfoln(gotext.Get("Searching AUR for updates..."))

_aurdata, err := u.aurCache.Get(ctx, &aur.Query{Needles: remoteNames, By: aur.Name})
var errs multierror.MultiError

aurdata, aurUp, develUp, err := u.GetAURUpgrades(ctx, enableDowngrade)
if err != nil {
errs.Add(err)

if err == nil {
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 {
u.log.OperationInfoln(gotext.Get("Checking development packages..."))

develUp = UpDevel(ctx, u.log, remote, aurdata, u.vcsStore)

u.vcsStore.CleanOrphans(remote)
}
}
}

aurPkgsAdded := []*aur.Pkg{}
Expand Down Expand Up @@ -233,6 +202,45 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
return aurUp, repoUp
}

func (u *UpgradeService) GetAURUpgrades(ctx context.Context, enableDowngrade bool) (
aurdata map[string]*aur.Pkg, aurUp, develUp UpSlice, err error,
) {
aurdata = make(map[string]*aur.Pkg)
remote := u.dbExecutor.InstalledRemotePackages()
remoteNames := u.dbExecutor.InstalledRemotePackageNames()

if !u.cfg.Mode.AtLeastAUR() {
return aurdata, aurUp, develUp, err
}

u.log.OperationInfoln(gotext.Get("Searching AUR for updates..."))

_aurdata, err := u.aurCache.Get(ctx, &aur.Query{Needles: remoteNames, By: aur.Name})
if err != nil {
return aurdata, aurUp, develUp, err
}

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 {
u.log.OperationInfoln(gotext.Get("Checking development packages..."))

develUp = UpDevel(ctx, u.log, remote, aurdata, u.vcsStore)

u.vcsStore.CleanOrphans(remote)
}

return aurdata, aurUp, develUp, nil
}

func (u *UpgradeService) GraphUpgrades(ctx context.Context,
graph *topo.Graph[string, *dep.InstallInfo],
enableDowngrade bool, filter Filter,
Expand Down
131 changes: 131 additions & 0 deletions pkg/upgrade/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,137 @@ func ptrString(s string) *string {
return &s
}

func TestUpgradeService_GetAURUpgrades(t *testing.T) {
t.Parallel()

remoteNames := []string{"yay", "example-git"}
remotePackages := func() map[string]mock.IPackage {
return map[string]mock.IPackage{
"yay": &mock.Package{
PName: "yay",
PBase: "yay",
PVersion: "10.2.3",
PReason: alpm.PkgReasonExplicit,
},
"example-git": &mock.Package{
PName: "example-git",
PBase: "example",
PVersion: "2.2.1",
PReason: alpm.PkgReasonDepend,
},
}
}

tests := []struct {
name string
mode parser.TargetMode
aurPkgs []aur.Pkg
vcsToUpgrade []string
wantAURDataKeys []string
wantAurUp []db.Upgrade
wantDevelUp []db.Upgrade
wantErr error
}{
{
name: "repo mode only skips aur upgrade checks",
mode: parser.ModeRepo,
wantAURDataKeys: []string{},
},
{
name: "aur and devel upgrades",
mode: parser.ModeAny,
vcsToUpgrade: []string{"example-git"},
aurPkgs: []aur.Pkg{
{Name: "yay", Version: "10.2.4", PackageBase: "yay"},
{Name: "example-git", Version: "2.3.0", PackageBase: "example"},
},
wantAURDataKeys: []string{"yay", "example-git"},
wantAurUp: []db.Upgrade{
{
Name: "yay",
Base: "yay",
Repository: "aur",
LocalVersion: "10.2.3",
RemoteVersion: "10.2.4",
Reason: alpm.PkgReasonExplicit,
},
{
Name: "example-git",
Base: "example",
Repository: "aur",
LocalVersion: "2.2.1",
RemoteVersion: "2.3.0",
Reason: alpm.PkgReasonDepend,
},
},
wantDevelUp: []db.Upgrade{
{
Name: "example-git",
Base: "example",
Repository: "devel",
LocalVersion: "2.2.1",
RemoteVersion: "latest-commit",
Reason: alpm.PkgReasonDepend,
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbExe := &mock.DBExecutor{
InstalledRemotePackageNamesFn: func() []string {
return append([]string(nil), remoteNames...)
},
InstalledRemotePackagesFn: func() map[string]mock.IPackage {
return remotePackages()
},
}

mockAUR := &mockaur.MockAUR{
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
require.Equal(t, remoteNames, query.Needles)
require.Equal(t, aur.Name, query.By)
return append([]aur.Pkg(nil), tt.aurPkgs...), nil
},
}

vcsStore := &vcs.Mock{
ToUpgradeReturn: tt.vcsToUpgrade,
}

logger := text.NewLogger(io.Discard, os.Stderr,
strings.NewReader(""), true, "test")

u := &UpgradeService{
log: logger,
aurCache: mockAUR,
dbExecutor: dbExe,
vcsStore: vcsStore,
cfg: &settings.Configuration{Mode: tt.mode, Devel: true},
AURWarnings: query.NewWarnings(logger),
}

aurdata, aurUp, develUp, err := u.GetAURUpgrades(context.Background(), false)

if tt.wantErr != nil {
require.ErrorIs(t, err, tt.wantErr)
} else {
require.NoError(t, err)
}

keys := make([]string, 0, len(aurdata))
for k := range aurdata {
keys = append(keys, k)
}
assert.ElementsMatch(t, tt.wantAURDataKeys, keys)

assert.ElementsMatch(t, tt.wantAurUp, aurUp.Up)
assert.ElementsMatch(t, tt.wantDevelUp, develUp.Up)
})
}
}

func TestUpgradeService_GraphUpgrades(t *testing.T) {
t.Parallel()
linuxDepInfo := &dep.InstallInfo{
Expand Down
Loading