Skip to content

Commit

Permalink
Merge handles.Aur and depOrder.Bases
Browse files Browse the repository at this point in the history
depOrder.Aur contains the order in which AUR packages are to be
installed. While depOrder.bases contains the actual package data
organized by pkgbase.

deoOrder.AUR is kind of counterintuitive, as it only contains one
package from each package base.

For example if you were to install libc++{,abi,experimental},
depOrder.Aur would only contain one of those packages, which one
actually being quite random. depOrder.Bases[pkg.Pkgbase] will then be
looked up and everything under that slice would be installed.

This means that the only real use depOrder.Aur has, is to give the
pkgbase. So to cut out the middleman, lets merge .Aur and .Bases into
a single field.

Doing this has also heped to spot som subtle bugs:

Fix subtle split package errors.

The number menus now correctly list and respect (installed) for bases
that have atleast one of their packages installed.

Entering package names in number menus now always expects the pkgbase
name instead of the random package which happened to make it into .Aur.

--rebuild and --redownload correctly handles split packages.

formatPkgbase is also used more.
  • Loading branch information
Morganamilo committed Aug 18, 2018
1 parent 3dc350d commit 43feb12
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 171 deletions.
16 changes: 8 additions & 8 deletions dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ func splitDbFromName(pkg string) (string, string) {
return "", split[0]
}

func getBases(pkgs map[string]*rpc.Pkg) map[string][]*rpc.Pkg {
bases := make(map[string][]*rpc.Pkg)

func getBases(pkgs map[string]*rpc.Pkg) []Base {
basesMap := make(map[string]Base)
for _, pkg := range pkgs {
_, ok := bases[pkg.PackageBase]
if !ok {
bases[pkg.PackageBase] = make([]*rpc.Pkg, 0)
}
bases[pkg.PackageBase] = append(bases[pkg.PackageBase], pkg)
basesMap[pkg.PackageBase] = append(basesMap[pkg.PackageBase], pkg)
}

bases := make([]Base, 0, len(basesMap))
for _, base := range basesMap {
bases = append(bases, base)
}

return bases
Expand Down
43 changes: 28 additions & 15 deletions depOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,48 @@ import (
rpc "github.com/mikkeloscar/aur"
)

type Base []*rpc.Pkg

func (b Base) Pkgbase() string {
return b[0].PackageBase
}

func (b Base) Version() string {
return b[0].Version
}

func (b Base) URLPath() string {
return b[0].URLPath
}

type depOrder struct {
Aur []*rpc.Pkg
Aur []Base
Repo []*alpm.Package
Runtime stringSet
Bases map[string][]*rpc.Pkg
}

func makeDepOrder() *depOrder {
return &depOrder{
make([]*rpc.Pkg, 0),
make([]Base, 0),
make([]*alpm.Package, 0),
make(stringSet),
make(map[string][]*rpc.Pkg),
}
}

func getDepOrder(dp *depPool) *depOrder {
do := makeDepOrder()
basesMap := make(map[string]Base)

for _, target := range dp.Targets {
dep := target.DepString()
aurPkg := dp.Aur[dep]
if aurPkg != nil && pkgSatisfies(aurPkg.Name, aurPkg.Version, dep) {
do.orderPkgAur(aurPkg, dp, true)
do.orderPkgAur(aurPkg, dp, basesMap, true)
}

aurPkg = dp.findSatisfierAur(dep)
if aurPkg != nil {
do.orderPkgAur(aurPkg, dp, true)
do.orderPkgAur(aurPkg, dp, basesMap, true)
}

repoPkg := dp.findSatisfierRepo(dep)
Expand All @@ -42,10 +55,14 @@ func getDepOrder(dp *depPool) *depOrder {
}
}

for _, base := range basesMap {
do.Aur = append(do.Aur, base)
}

return do
}

func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {
func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, basesMap map[string]Base, runtime bool) {
if runtime {
do.Runtime.set(pkg.Name)
}
Expand All @@ -55,7 +72,7 @@ func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {
for _, dep := range deps {
aurPkg := dp.findSatisfierAur(dep)
if aurPkg != nil {
do.orderPkgAur(aurPkg, dp, runtime && i == 0)
do.orderPkgAur(aurPkg, dp, basesMap, runtime && i == 0)
}

repoPkg := dp.findSatisfierRepo(dep)
Expand All @@ -65,11 +82,7 @@ func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {
}
}

if _, ok := do.Bases[pkg.PackageBase]; !ok {
do.Aur = append(do.Aur, pkg)
do.Bases[pkg.PackageBase] = make([]*rpc.Pkg, 0)
}
do.Bases[pkg.PackageBase] = append(do.Bases[pkg.PackageBase], pkg)
basesMap[pkg.PackageBase] = append(basesMap[pkg.PackageBase], pkg)
}

func (do *depOrder) orderPkgRepo(pkg *alpm.Package, dp *depPool, runtime bool) {
Expand All @@ -92,7 +105,7 @@ func (do *depOrder) orderPkgRepo(pkg *alpm.Package, dp *depPool, runtime bool) {

func (do *depOrder) HasMake() bool {
lenAur := 0
for _, base := range do.Bases {
for _, base := range do.Aur {
lenAur += len(base)
}

Expand All @@ -102,7 +115,7 @@ func (do *depOrder) HasMake() bool {
func (do *depOrder) getMake() []string {
makeOnly := make([]string, 0, len(do.Aur)+len(do.Repo)-len(do.Runtime))

for _, base := range do.Bases {
for _, base := range do.Aur {
for _, pkg := range base {
if !do.Runtime.get(pkg.Name) {
makeOnly = append(makeOnly, pkg.Name)
Expand Down
Loading

0 comments on commit 43feb12

Please sign in to comment.