From ea5a94e0f8bb5f76879099e6d319c0c0102231c2 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Fri, 22 Jun 2018 15:17:34 +0100 Subject: [PATCH] Remove default usage of --ask --ask is no longer used when installing AUR packages, instead pass no confirm when we know there are no conflicts and wait for manual confirmation when there are. This means that when there are no conflicts there should be no change in behaviour and the user will not need to intervene at all. The old behaviour can still be used with --useask. --- cmd.go | 4 ++++ config.go | 2 ++ depCheck.go | 11 ++++++++--- install.go | 34 ++++++++++++++++++++++++---------- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/cmd.go b/cmd.go index 67607085..aaf99f74 100644 --- a/cmd.go +++ b/cmd.go @@ -341,6 +341,10 @@ func handleConfig(option, value string) bool { config.EditMenu = true case "noeditmenu": config.EditMenu = false + case "useask": + config.UseAsk = true + case "nouseask": + config.UseAsk = false case "a", "aur": mode = ModeAUR case "repo": diff --git a/config.go b/config.go index 2afca209..18f47161 100644 --- a/config.go +++ b/config.go @@ -69,6 +69,7 @@ type Configuration struct { CleanMenu bool `json:"cleanmenu"` DiffMenu bool `json:"diffmenu"` EditMenu bool `json:"editmenu"` + UseAsk bool `json:"useask"` } var version = "7.885" @@ -177,6 +178,7 @@ func defaultSettings(config *Configuration) { config.CleanMenu = true config.DiffMenu = true config.EditMenu = false + config.UseAsk = false } // Editor returns the preferred system editor. diff --git a/depCheck.go b/depCheck.go index 08e9a632..3ed42150 100644 --- a/depCheck.go +++ b/depCheck.go @@ -124,7 +124,7 @@ func (dp *depPool) checkReverseConflicts(conflicts mapStringSet) { }) } -func (dp *depPool) CheckConflicts() error { +func (dp *depPool) CheckConflicts() (mapStringSet, error) { var wg sync.WaitGroup innerConflicts := make(mapStringSet) conflicts := make(mapStringSet) @@ -159,12 +159,17 @@ func (dp *depPool) CheckConflicts() error { fmt.Println(str) } - return fmt.Errorf("Unresolvable package conflicts, aborting") + return nil, fmt.Errorf("Unresolvable package conflicts, aborting") } if len(conflicts) != 0 { fmt.Println() fmt.Println(bold(red(arrow)), bold("Package conflicts found:")) + + if !config.UseAsk { + fmt.Println(bold(red(arrow)), bold("You will have to confirm these when installing")) + } + for name, pkgs := range conflicts { str := red(bold(smallArrow)) + " Installing " + cyan(name) + " will remove:" for pkg := range pkgs { @@ -178,7 +183,7 @@ func (dp *depPool) CheckConflicts() error { fmt.Println() } - return nil + return conflicts, nil } type missing struct { diff --git a/install.go b/install.go index b890bf6a..52464eda 100644 --- a/install.go +++ b/install.go @@ -116,7 +116,7 @@ func install(parser *arguments) error { return fmt.Errorf(bold(red(arrow)) + " Refusing to install AUR Packages as root, Aborting.") } - err = dp.CheckConflicts() + conflicts, err := dp.CheckConflicts() if err != nil { return err } @@ -279,17 +279,12 @@ func install(parser *arguments) error { } } - //conflicts have been checked so answer y for them - ask, _ := strconv.Atoi(cmdArgs.globals["ask"]) - uask := alpm.QuestionType(ask) | alpm.QuestionTypeConflictPkg - cmdArgs.globals["ask"] = fmt.Sprint(uask) - err = downloadPkgBuildsSources(do.Aur, do.Bases, incompatible) if err != nil { return err } - err = buildInstallPkgBuilds(dp, do, srcinfosStale, parser, incompatible) + err = buildInstallPkgBuilds(dp, do, srcinfosStale, parser, incompatible, conflicts) if err != nil { return err } @@ -745,7 +740,7 @@ func downloadPkgBuildsSources(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, inco return } -func buildInstallPkgBuilds(dp *depPool, do *depOrder, srcinfos map[string]*gopkg.PKGBUILD, parser *arguments, incompatible stringSet) error { +func buildInstallPkgBuilds(dp *depPool, do *depOrder, srcinfos map[string]*gopkg.PKGBUILD, parser *arguments, incompatible stringSet, conflicts mapStringSet) error { for _, pkg := range do.Aur { dir := filepath.Join(config.BuildDir, pkg.PackageBase) built := true @@ -807,6 +802,7 @@ func buildInstallPkgBuilds(dp *depPool, do *depOrder, srcinfos map[string]*gopkg arguments.clearTargets() arguments.op = "U" arguments.delArg("confirm") + arguments.delArg("noconfirm") arguments.delArg("c", "clean") arguments.delArg("q", "quiet") arguments.delArg("q", "quiet") @@ -814,6 +810,26 @@ func buildInstallPkgBuilds(dp *depPool, do *depOrder, srcinfos map[string]*gopkg arguments.delArg("u", "sysupgrade") arguments.delArg("w", "downloadonly") + oldConfirm := config.NoConfirm + + //conflicts have been checked so answer y for them + if config.UseAsk { + ask, _ := strconv.Atoi(cmdArgs.globals["ask"]) + uask := alpm.QuestionType(ask) | alpm.QuestionTypeConflictPkg + cmdArgs.globals["ask"] = fmt.Sprint(uask) + } else { + conflict := false + for _, split := range do.Bases[pkg.PackageBase] { + if _, ok := conflicts[split.Name]; ok { + conflict = true + } + } + + if !conflict { + config.NoConfirm = true + } + } + depArguments := makeArguments() depArguments.addArg("D", "asdeps") expArguments := makeArguments() @@ -850,8 +866,6 @@ func buildInstallPkgBuilds(dp *depPool, do *depOrder, srcinfos map[string]*gopkg } } - oldConfirm := config.NoConfirm - config.NoConfirm = true err = passToPacman(arguments) if err != nil { return err