Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(yay): skip confirmed confirms #2107

Merged
merged 3 commits into from
Apr 11, 2023
Merged
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
40 changes: 27 additions & 13 deletions aur_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type (
targetMode parser.TargetMode
downloadOnly bool
log *text.Logger

manualConfirmRequired bool
}
)

Expand All @@ -37,14 +39,15 @@ func NewInstaller(dbExecutor db.Executor,
downloadOnly bool, logger *text.Logger,
) *Installer {
return &Installer{
dbExecutor: dbExecutor,
postInstallHooks: []PostInstallHookFunc{},
failedAndIgnored: map[string]error{},
exeCmd: exeCmd,
vcsStore: vcsStore,
targetMode: targetMode,
downloadOnly: downloadOnly,
log: logger,
dbExecutor: dbExecutor,
postInstallHooks: []PostInstallHookFunc{},
failedAndIgnored: map[string]error{},
exeCmd: exeCmd,
vcsStore: vcsStore,
targetMode: targetMode,
downloadOnly: downloadOnly,
log: logger,
manualConfirmRequired: true,
}
}

Expand Down Expand Up @@ -83,7 +86,10 @@ func (installer *Installer) Install(ctx context.Context,
targets []map[string]*dep.InstallInfo,
pkgBuildDirs map[string]string,
excluded []string,
manualConfirmRequired bool,
) error {
installer.log.Debugln("manualConfirmRequired:", manualConfirmRequired)
installer.manualConfirmRequired = manualConfirmRequired
// Reorganize targets into layers of dependencies
var errMulti multierror.MultiError
for i := len(targets) - 1; i >= 0; i-- {
Expand Down Expand Up @@ -117,6 +123,10 @@ func mergeLayers(layer1, layer2 map[string]*dep.InstallInfo) map[string]*dep.Ins
return layer1
}

func (installer *Installer) appendNoConfirm() bool {
return !installer.manualConfirmRequired || settings.NoConfirm
}

func (installer *Installer) handleLayer(ctx context.Context,
cmdArgs *parser.Arguments,
layer map[string]*dep.InstallInfo,
Expand Down Expand Up @@ -165,16 +175,17 @@ func (installer *Installer) handleLayer(ctx context.Context,
}
}

text.Debugln("syncDeps", syncDeps, "SyncExp", syncExp,
installer.log.Debugln("syncDeps", syncDeps, "SyncExp", syncExp,
"aurDeps", aurDeps, "aurExp", aurExp, "upgrade", upgradeSync)

errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp, excluded, upgradeSync)
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp,
excluded, upgradeSync, installer.appendNoConfirm())
if errShow != nil {
return ErrInstallRepoPkgs
}

errAur := installer.installAURPackages(ctx, cmdArgs, aurDeps, aurExp,
nameToBaseMap, pkgBuildDirs, true, lastLayer)
nameToBaseMap, pkgBuildDirs, true, lastLayer, installer.appendNoConfirm())

return errAur
}
Expand All @@ -185,6 +196,7 @@ func (installer *Installer) installAURPackages(ctx context.Context,
nameToBase, pkgBuildDirsByBase map[string]string,
installIncompatible bool,
lastLayer bool,
noConfirm bool,
) error {
all := aurDepNames.Union(aurExpNames).ToSlice()
if len(all) == 0 {
Expand Down Expand Up @@ -232,7 +244,8 @@ func (installer *Installer) installAURPackages(ctx context.Context,
}
}

if err := installPkgArchive(ctx, installer.exeCmd, installer.targetMode, installer.vcsStore, cmdArgs, pkgArchives); err != nil {
if err := installPkgArchive(ctx, installer.exeCmd, installer.targetMode,
installer.vcsStore, cmdArgs, pkgArchives, noConfirm); err != nil {
return fmt.Errorf("%s - %w", fmt.Sprintf(gotext.Get("error installing:")+" %v", pkgArchives), err)
}

Expand Down Expand Up @@ -361,6 +374,7 @@ func (installer *Installer) installSyncPackages(ctx context.Context, cmdArgs *pa
syncExp mapset.Set[string], // repo targets that are exp
excluded []string,
upgrade bool, // run even without targets
noConfirm bool,
) error {
repoTargets := syncDeps.Union(syncExp).ToSlice()
if len(repoTargets) == 0 && !upgrade {
Expand All @@ -379,7 +393,7 @@ func (installer *Installer) installSyncPackages(ctx context.Context, cmdArgs *pa
}

errShow := installer.exeCmd.Show(installer.exeCmd.BuildPacmanCmd(ctx,
arguments, installer.targetMode, settings.NoConfirm))
arguments, installer.targetMode, noConfirm))

if errD := asdeps(ctx, installer.exeCmd, installer.targetMode, cmdArgs, syncDeps.ToSlice()); errD != nil {
return errD
Expand Down
10 changes: 5 additions & 5 deletions aur_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestInstaller_InstallNeeded(t *testing.T) {
},
}

errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{})
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{}, false)
require.NoError(td, errI)

require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
"jellyfin": tmpDirJfin,
}

errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
require.NoError(td, errI)

require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
Expand Down Expand Up @@ -598,7 +598,7 @@ func TestInstaller_CompileFailed(t *testing.T) {
"yay": tmpDir,
}

errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
if tc.wantErrInstall {
require.Error(td, errI)
} else {
Expand Down Expand Up @@ -755,7 +755,7 @@ func TestInstaller_InstallSplitPackage(t *testing.T) {
"jellyfin": tmpDir,
}

errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
require.NoError(td, errI)

require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
Expand Down Expand Up @@ -905,7 +905,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
},
}

errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{})
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{}, false)
require.NoError(td, errI)

require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
Expand Down
1 change: 0 additions & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ func displayNumberMenu(ctx context.Context, cfg *settings.Configuration, pkgS []
}

// modify the arguments to pass for the install
cmdArgs.Op = "S"
cmdArgs.Targets = targets

if len(cmdArgs.Targets) == 0 {
Expand Down
8 changes: 5 additions & 3 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func buildInstallPkgbuilds(
if !satisfied || !cfg.BatchInstall {
text.Debugln("non batch installing archives:", pkgArchives)
errArchive := installPkgArchive(ctx, cfg.Runtime.CmdBuilder,
cfg.Mode, cfg.Runtime.VCSStore, cmdArgs, pkgArchives)
cfg.Mode, cfg.Runtime.VCSStore, cmdArgs, pkgArchives, settings.NoConfirm)
errReason := setInstallReason(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cmdArgs, deps, exp)

deps = make([]string, 0)
Expand Down Expand Up @@ -802,7 +802,8 @@ func buildInstallPkgbuilds(
}

text.Debugln("installing archives:", pkgArchives)
errArchive := installPkgArchive(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cfg.Runtime.VCSStore, cmdArgs, pkgArchives)
errArchive := installPkgArchive(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cfg.Runtime.VCSStore,
cmdArgs, pkgArchives, settings.NoConfirm)
if errArchive != nil {
go cfg.Runtime.VCSStore.RemovePackages([]string{do.Aur[len(do.Aur)-1].String()})
}
Expand All @@ -823,6 +824,7 @@ func installPkgArchive(ctx context.Context,
vcsStore vcs.Store,
cmdArgs *parser.Arguments,
pkgArchives []string,
noConfirm bool,
) error {
if len(pkgArchives) == 0 {
return nil
Expand All @@ -845,7 +847,7 @@ func installPkgArchive(ctx context.Context,
arguments.AddTarget(pkgArchives...)

if errShow := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
arguments, mode, settings.NoConfirm)); errShow != nil {
arguments, mode, noConfirm)); errShow != nil {
return errShow
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Configuration struct {
NewInstallEngine bool `json:"newinstallengine"`
Debug bool `json:"debug"`
UseRPC bool `json:"rpc"`
DoubleConfirm bool `json:"doubleconfirm"` // confirm install before and after build

CompletionPath string `json:"-"`
VCSFilePath string `json:"-"`
Expand Down Expand Up @@ -239,6 +240,7 @@ func DefaultConfig(version string) *Configuration {
Version: version,
Debug: false,
UseRPC: true,
DoubleConfirm: true,
Runtime: &Runtime{
Logger: text.GlobalLogger,
},
Expand Down
10 changes: 7 additions & 3 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ func (o *OperationService) Run(ctx context.Context,
return errInstall
}

cleanFunc := preparer.ShouldCleanMakeDeps(cmdArgs)
if cleanFunc != nil {
if cleanFunc := preparer.ShouldCleanMakeDeps(cmdArgs); cleanFunc != nil {
installer.AddPostInstallHook(cleanFunc)
}

Expand Down Expand Up @@ -158,7 +157,8 @@ func (o *OperationService) Run(ctx context.Context,
return errPGP
}

if errInstall := installer.Install(ctx, cmdArgs, targets, pkgBuildDirs, excluded); errInstall != nil {
if errInstall := installer.Install(ctx, cmdArgs, targets, pkgBuildDirs,
excluded, o.manualConfirmRequired(cmdArgs)); errInstall != nil {
return errInstall
}

Expand All @@ -181,6 +181,10 @@ func (o *OperationService) Run(ctx context.Context,
return multiErr.Return()
}

func (o *OperationService) manualConfirmRequired(cmdArgs *parser.Arguments) bool {
return (!cmdArgs.ExistsArg("u", "sysupgrade") && cmdArgs.Op != "Y") || o.cfg.DoubleConfirm
}

func confirmIncompatible(incompatible []string) error {
if len(incompatible) > 0 {
text.Warnln(gotext.Get("The following packages are not compatible with your architecture:"))
Expand Down
1 change: 1 addition & 0 deletions sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ pkgname = python-vosk
}

cfg := &settings.Configuration{
DoubleConfirm: true,
NewInstallEngine: true,
RemoveMake: "no",
BuildDir: tmpDir,
Expand Down