Merge pull request #302 from Morganamilo/fix#287

Only pass needed upgrades to deptree
This commit is contained in:
J Guerreiro 2018-04-02 12:48:53 +02:00 committed by GitHub
commit 5b7daa129a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 43 deletions

View File

@ -22,9 +22,13 @@ func install(parser *arguments) error {
var toClean []*rpc.Pkg var toClean []*rpc.Pkg
var toEdit []*rpc.Pkg var toEdit []*rpc.Pkg
var aurUp upSlice
var repoUp upSlice
removeMake := false removeMake := false
srcinfosStale := make(map[string]*gopkg.PKGBUILD) srcinfosStale := make(map[string]*gopkg.PKGBUILD)
srcinfos := make(map[string]*gopkg.PKGBUILD) srcinfos := make(map[string]*gopkg.PKGBUILD)
//remotenames: names of all non repo packages on the system //remotenames: names of all non repo packages on the system
_, _, _, remoteNames, err := filterPackages() _, _, _, remoteNames, err := filterPackages()
if err != nil { if err != nil {
@ -35,9 +39,21 @@ func install(parser *arguments) error {
//place //place
remoteNamesCache := sliceToStringSet(remoteNames) remoteNamesCache := sliceToStringSet(remoteNames)
//if we are doing -u also request every non repo package on the system //if we are doing -u also request all packages needing update
if parser.existsArg("u", "sysupgrade") { if parser.existsArg("u", "sysupgrade") {
requestTargets = append(requestTargets, remoteNames...) aurUp, repoUp, err = upList()
if err != nil {
return err
}
for _, up := range aurUp {
requestTargets = append(requestTargets, up.Name)
}
for _, up := range repoUp {
requestTargets = append(requestTargets, up.Name)
}
} }
//if len(aurTargets) > 0 || parser.existsArg("u", "sysupgrade") && len(remoteNames) > 0 { //if len(aurTargets) > 0 || parser.existsArg("u", "sysupgrade") && len(remoteNames) > 0 {
@ -56,10 +72,7 @@ func install(parser *arguments) error {
parser.targets.set(name) parser.targets.set(name)
} }
//only error if direct targets or deps are missing if len(dt.Missing) > 0 {
for missing := range dt.Missing {
_, missingName := splitDbFromName(missing)
if !remoteNamesCache.get(missingName) || parser.targets.get(missingName) {
str := bold(red(arrow+" Error: ")) + "Could not find all required packages:" str := bold(red(arrow+" Error: ")) + "Could not find all required packages:"
for name := range dt.Missing { for name := range dt.Missing {
@ -68,7 +81,6 @@ func install(parser *arguments) error {
return fmt.Errorf("%s", str) return fmt.Errorf("%s", str)
} }
}
//create the arguments to pass for the repo install //create the arguments to pass for the repo install
arguments := parser.copy() arguments := parser.copy()
@ -77,7 +89,7 @@ func install(parser *arguments) error {
arguments.targets = make(stringSet) arguments.targets = make(stringSet)
if parser.existsArg("u", "sysupgrade") { if parser.existsArg("u", "sysupgrade") {
ignore, aurUp, err := upgradePkgs(dt) ignore, aurUp, err := upgradePkgs(aurUp, repoUp)
if err != nil { if err != nil {
return err return err
} }
@ -88,16 +100,6 @@ func install(parser *arguments) error {
for pkg := range aurUp { for pkg := range aurUp {
parser.addTarget(pkg) parser.addTarget(pkg)
} }
//discard stuff thats
//not a target and
//not an upgrade and
//is installed
for pkg := range dt.Aur {
if !parser.targets.get(pkg) && remoteNamesCache.get(pkg) {
delete(dt.Aur, pkg)
}
}
} }
hasAur := false hasAur := false
@ -112,7 +114,7 @@ func install(parser *arguments) error {
return fmt.Errorf(red(arrow + " Refusing to install AUR Packages as root, Aborting.")) return fmt.Errorf(red(arrow + " Refusing to install AUR Packages as root, Aborting."))
} }
dc, err = getDepCatagories(parser.formatTargets(), dt) dc, err = getDepCatagories(requestTargets, dt)
if err != nil { if err != nil {
return err return err
} }

View File

@ -288,9 +288,7 @@ func printNumberOfUpdates() error {
//todo //todo
old := os.Stdout // keep backup of the real stdout old := os.Stdout // keep backup of the real stdout
os.Stdout = nil os.Stdout = nil
_, _, localNames, remoteNames, err := filterPackages() aurUp, repoUp, err := upList()
dt, _ := getDepTree(append(localNames, remoteNames...))
aurUp, repoUp, err := upList(dt)
os.Stdout = old // restoring the real stdout os.Stdout = old // restoring the real stdout
if err != nil { if err != nil {
return err return err
@ -302,13 +300,11 @@ func printNumberOfUpdates() error {
//TODO: Make it less hacky //TODO: Make it less hacky
func printUpdateList(parser *arguments) error { func printUpdateList(parser *arguments) error {
old := os.Stdout // Keep backup of the real stdout old := os.Stdout // keep backup of the real stdout
os.Stdout = nil os.Stdout = nil
_, _, localNames, remoteNames, err := filterPackages() _, _, localNames, remoteNames, err := filterPackages()
dt, _ := getDepTree(append(localNames, remoteNames...)) aurUp, repoUp, err := upList()
aurUp, repoUp, err := upList(dt) os.Stdout = old // restoring the real stdout
os.Stdout = old // Restoring the real stdout
if err != nil { if err != nil {
return err return err
} }

View File

@ -9,6 +9,7 @@ import (
"sync" "sync"
alpm "github.com/jguer/go-alpm" alpm "github.com/jguer/go-alpm"
rpc "github.com/mikkeloscar/aur"
pkgb "github.com/mikkeloscar/gopkgbuild" pkgb "github.com/mikkeloscar/gopkgbuild"
) )
@ -88,7 +89,7 @@ func getVersionDiff(oldVersion, newversion string) (left, right string) {
} }
// upList returns lists of packages to upgrade from each source. // upList returns lists of packages to upgrade from each source.
func upList(dt *depTree) (aurUp upSlice, repoUp upSlice, err error) { func upList() (aurUp upSlice, repoUp upSlice, err error) {
local, remote, _, remoteNames, err := filterPackages() local, remote, _, remoteNames, err := filterPackages()
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -111,7 +112,7 @@ func upList(dt *depTree) (aurUp upSlice, repoUp upSlice, err error) {
fmt.Println(bold(cyan("::") + " Searching AUR for updates...")) fmt.Println(bold(cyan("::") + " Searching AUR for updates..."))
wg.Add(1) wg.Add(1)
go func() { go func() {
aurUp, aurErr = upAUR(remote, remoteNames, dt) aurUp, aurErr = upAUR(remote, remoteNames)
wg.Done() wg.Done()
}() }()
@ -205,9 +206,20 @@ func upDevel(remote []alpm.Package) (toUpgrade upSlice, err error) {
// upAUR gathers foreign packages and checks if they have new versions. // upAUR gathers foreign packages and checks if they have new versions.
// Output: Upgrade type package list. // Output: Upgrade type package list.
func upAUR(remote []alpm.Package, remoteNames []string, dt *depTree) (toUpgrade upSlice, err error) { func upAUR(remote []alpm.Package, remoteNames []string) (upSlice, error) {
toUpgrade := make(upSlice, 0)
_pkgdata, err := aurInfo(remoteNames)
if err != nil {
return nil, err
}
pkgdata := make(map[string]*rpc.Pkg)
for _, pkg := range _pkgdata {
pkgdata[pkg.Name] = pkg
}
for _, pkg := range remote { for _, pkg := range remote {
aurPkg, ok := dt.Aur[pkg.Name()] aurPkg, ok := pkgdata[pkg.Name()]
if !ok { if !ok {
continue continue
} }
@ -224,7 +236,7 @@ func upAUR(remote []alpm.Package, remoteNames []string, dt *depTree) (toUpgrade
} }
} }
return return toUpgrade, nil
} }
// upRepo gathers local packages and checks if they have new versions. // upRepo gathers local packages and checks if they have new versions.
@ -253,15 +265,12 @@ func upRepo(local []alpm.Package) (upSlice, error) {
} }
// upgradePkgs handles updating the cache and installing updates. // upgradePkgs handles updating the cache and installing updates.
func upgradePkgs(dt *depTree) (stringSet, stringSet, error) { func upgradePkgs(aurUp, repoUp upSlice) (stringSet, stringSet, error) {
ignore := make(stringSet) ignore := make(stringSet)
aurNames := make(stringSet) aurNames := make(stringSet)
aurUp, repoUp, err := upList(dt) if len(aurUp)+len(repoUp) == 0 {
if err != nil { return ignore, aurNames, nil
return ignore, aurNames, err
} else if len(aurUp)+len(repoUp) == 0 {
return ignore, aurNames, err
} }
sort.Sort(repoUp) sort.Sort(repoUp)