mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
fix(groups): fix sync group getting passed to reason setter (#2148)
fix sync group install #2137
This commit is contained in:
parent
966bfb74ee
commit
f7731d7cf9
@ -136,7 +136,8 @@ func (installer *Installer) handleLayer(ctx context.Context,
|
||||
) error {
|
||||
// Install layer
|
||||
nameToBaseMap := make(map[string]string, 0)
|
||||
syncDeps, syncExp := mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
|
||||
syncDeps, syncExp, syncGroups := mapset.NewThreadUnsafeSet[string](),
|
||||
mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
|
||||
aurDeps, aurExp := mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
|
||||
|
||||
upgradeSync := false
|
||||
@ -162,6 +163,11 @@ func (installer *Installer) handleLayer(ctx context.Context,
|
||||
}
|
||||
compositePkgName := fmt.Sprintf("%s/%s", *info.SyncDBName, name)
|
||||
|
||||
if info.IsGroup {
|
||||
syncGroups.Add(compositePkgName)
|
||||
continue
|
||||
}
|
||||
|
||||
switch info.Reason {
|
||||
case dep.Explicit:
|
||||
if cmdArgs.ExistsArg("asdeps", "asdep") {
|
||||
@ -178,7 +184,7 @@ func (installer *Installer) handleLayer(ctx context.Context,
|
||||
installer.log.Debugln("syncDeps", syncDeps, "SyncExp", syncExp,
|
||||
"aurDeps", aurDeps, "aurExp", aurExp, "upgrade", upgradeSync)
|
||||
|
||||
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp,
|
||||
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp, syncGroups,
|
||||
excluded, upgradeSync, installer.appendNoConfirm())
|
||||
if errShow != nil {
|
||||
return ErrInstallRepoPkgs
|
||||
@ -372,11 +378,12 @@ func (installer *Installer) getNewTargets(pkgdests map[string]string, name strin
|
||||
func (installer *Installer) installSyncPackages(ctx context.Context, cmdArgs *parser.Arguments,
|
||||
syncDeps, // repo targets that are deps
|
||||
syncExp mapset.Set[string], // repo targets that are exp
|
||||
syncGroups mapset.Set[string], // repo targets that are groups
|
||||
excluded []string,
|
||||
upgrade bool, // run even without targets
|
||||
noConfirm bool,
|
||||
) error {
|
||||
repoTargets := syncDeps.Union(syncExp).ToSlice()
|
||||
repoTargets := syncDeps.Union(syncExp).Union(syncGroups).ToSlice()
|
||||
if len(repoTargets) == 0 && !upgrade {
|
||||
return nil
|
||||
}
|
||||
|
@ -934,3 +934,104 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstaller_InstallGroup(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
f, err := os.OpenFile(makepkgBin, os.O_RDONLY|os.O_CREATE, 0o755)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
f, err = os.OpenFile(pacmanBin, os.O_RDONLY|os.O_CREATE, 0o755)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
type testCase struct {
|
||||
desc string
|
||||
wantShow []string
|
||||
wantCapture []string
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
desc: "group",
|
||||
wantShow: []string{
|
||||
"pacman -S --noconfirm --config -- community/kubernetes-tools",
|
||||
},
|
||||
wantCapture: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(td *testing.T) {
|
||||
tmpDir := td.TempDir()
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
return "", "", nil
|
||||
}
|
||||
|
||||
showOverride := func(cmd *exec.Cmd) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
mockDB := &mock.DBExecutor{}
|
||||
mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
MakepkgBin: makepkgBin,
|
||||
SudoBin: "su",
|
||||
PacmanBin: pacmanBin,
|
||||
Runner: mockRunner,
|
||||
SudoLoopEnabled: false,
|
||||
}
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, true, NewTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddTarget("kubernetes-tools")
|
||||
|
||||
pkgBuildDirs := map[string]string{}
|
||||
|
||||
targets := []map[string]*dep.InstallInfo{
|
||||
{
|
||||
"kubernetes-tools": {
|
||||
Source: dep.Sync,
|
||||
Reason: dep.Explicit,
|
||||
Version: "",
|
||||
IsGroup: true,
|
||||
SyncDBName: ptrString("community"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
require.Len(td, mockRunner.CaptureCalls, len(tc.wantCapture))
|
||||
require.Empty(td, installer.failedAndIgnored)
|
||||
|
||||
for i, call := range mockRunner.ShowCalls {
|
||||
show := call.Args[0].(*exec.Cmd).String()
|
||||
show = strings.ReplaceAll(show, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
show = strings.ReplaceAll(show, makepkgBin, "makepkg")
|
||||
show = strings.ReplaceAll(show, pacmanBin, "pacman")
|
||||
|
||||
// options are in a different order on different systems and on CI root user is used
|
||||
assert.Subset(td, strings.Split(show, " "), strings.Split(tc.wantShow[i], " "), show)
|
||||
}
|
||||
|
||||
for i, call := range mockRunner.CaptureCalls {
|
||||
capture := call.Args[0].(*exec.Cmd).String()
|
||||
capture = strings.ReplaceAll(capture, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
capture = strings.ReplaceAll(capture, makepkgBin, "makepkg")
|
||||
capture = strings.ReplaceAll(capture, pacmanBin, "pacman")
|
||||
assert.Subset(td, strings.Split(capture, " "), strings.Split(tc.wantCapture[i], " "), capture)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ type InstallInfo struct {
|
||||
AURBase *string
|
||||
SyncDBName *string
|
||||
|
||||
IsGroup bool
|
||||
Upgrade bool
|
||||
Devel bool
|
||||
}
|
||||
@ -161,6 +162,7 @@ func (g *Grapher) GraphFromTargets(ctx context.Context,
|
||||
Reason: Explicit,
|
||||
Version: "",
|
||||
SyncDBName: &dbName,
|
||||
IsGroup: true,
|
||||
},
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user