From 28515c8beb5da851f8c37bf7aa70e210e0e2163d Mon Sep 17 00:00:00 2001 From: Jguer Date: Wed, 7 Feb 2018 12:36:51 +0000 Subject: [PATCH] adds conflicting packages prompt --- install.go | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 7 deletions(-) diff --git a/install.go b/install.go index eebd3a959..74e476c4b 100644 --- a/install.go +++ b/install.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" + alpm "github.com/jguer/go-alpm" rpc "github.com/mikkeloscar/aur" gopkg "github.com/mikkeloscar/gopkgbuild" ) @@ -37,7 +38,7 @@ func install(parser *arguments) error { if len(aurs) != 0 { //todo make pretty - fmt.Println("Resolving Dependencies") + fmt.Println(greenFg(arrow), greenFg("Resolving Dependencies")) dt, err := getDepTree(aurs) if err != nil { @@ -75,12 +76,19 @@ func install(parser *arguments) error { askCleanBuilds(dc.AurMake) askCleanBuilds(dc.Aur) - fmt.Println() - if !continueTask("Proceed with download?", "nN") { + if !continueTask("Proceed with install?", "nN") { return fmt.Errorf("Aborting due to user") } + // if !continueTask("Proceed with download?", "nN") { + // return fmt.Errorf("Aborting due to user") + // } + + err = checkForConflicts(dc.Aur, dc.AurMake, dc.Repo, dc.RepoMake) + if err != nil { + return err + } err = dowloadPkgBuilds(dc.AurMake) if err != nil { @@ -94,9 +102,9 @@ func install(parser *arguments) error { askEditPkgBuilds(dc.AurMake) askEditPkgBuilds(dc.Aur) - if !continueTask("Proceed with install?", "nN") { - return fmt.Errorf("Aborting due to user") - } + // if !continueTask("Proceed with install?", "nN") { + // return fmt.Errorf("Aborting due to user") + // } err = downloadPkgBuildsSources(dc.AurMake) if err != nil { @@ -122,7 +130,7 @@ func install(parser *arguments) error { } removeArguments := makeArguments() - removeArguments.addArg("R") + removeArguments.addOP("R") for _, pkg := range dc.RepoMake { removeArguments.addTarget(pkg.Name()) @@ -132,7 +140,10 @@ func install(parser *arguments) error { removeArguments.addTarget(pkg.Name) } + oldValue := config.NoConfirm + config.NoConfirm = true passToPacman(removeArguments) + config.NoConfirm = oldValue } return nil @@ -153,6 +164,76 @@ func askCleanBuilds(pkgs []*rpc.Pkg) { } } +func checkForConflicts(aur []*rpc.Pkg, aurMake []*rpc.Pkg, repo []*alpm.Package, + repoMake []*alpm.Package) error { + + localDb, err := alpmHandle.LocalDb() + if err != nil { + return err + } + var toRemove []string + + for _, pkg := range aur { + for _, cpkg := range pkg.Conflicts { + if _, err := localDb.PkgByName(cpkg); err == nil { + toRemove = append(toRemove, cpkg) + } + } + } + + for _, pkg := range aurMake { + for _, cpkg := range pkg.Conflicts { + if _, err := localDb.PkgByName(cpkg); err == nil { + toRemove = append(toRemove, cpkg) + } + } + } + + for _, pkg := range repo { + pkg.Conflicts().ForEach(func(conf alpm.Depend) error { + if _, err := localDb.PkgByName(conf.Name); err == nil { + toRemove = append(toRemove, conf.Name) + } + return nil + }) + } + + for _, pkg := range repoMake { + pkg.Conflicts().ForEach(func(conf alpm.Depend) error { + if _, err := localDb.PkgByName(conf.Name); err == nil { + toRemove = append(toRemove, conf.Name) + } + return nil + }) + } + + if len(toRemove) != 0 { + fmt.Println( + redFg("The following packages conflict with packages to install:")) + for _, pkg := range toRemove { + fmt.Println(yellowFg(pkg)) + } + + if !continueTask("Remove conflicting package(s)?", "nN") { + return fmt.Errorf("Aborting due to user") + } + + removeArguments := makeArguments() + removeArguments.addArg("R", "d", "d") + + for _, pkg := range toRemove { + removeArguments.addTarget(pkg) + } + + oldValue := config.NoConfirm + config.NoConfirm = true + passToPacman(removeArguments) + config.NoConfirm = oldValue + } + + return nil +} + func askEditPkgBuilds(pkgs []*rpc.Pkg) { for _, pkg := range pkgs { dir := config.BuildDir + pkg.PackageBase + "/"