New dependency parsing method. Halved handle opens

This commit is contained in:
Jguer 2016-12-16 00:40:12 +00:00
parent 14a1f93d5a
commit cfb0efea45
2 changed files with 53 additions and 81 deletions

View file

@ -394,17 +394,24 @@ func (a *Result) Dependencies() (runDeps [2][]string, makeDeps [2][]string, err
q = append(q, *a)
}
depSearch := pacman.BuildDependencies(a.Depends)
if len(a.Depends) != 0 {
runDeps[0], runDeps[1], err = pacman.DepSatisfier(q[0].Depends)
fmt.Println("\x1b[1;32m=>\x1b[1;33m Dependencies: \x1b[0m")
printDeps(runDeps[0], runDeps[1])
runDeps[0], runDeps[1] = depSearch(q[0].Depends, true, false)
if len(runDeps[0]) != 0 || len(runDeps[1]) != 0 {
fmt.Println("\x1b[1;32m=>\x1b[1;33m Run Dependencies: \x1b[0m")
printDeps(runDeps[0], runDeps[1])
}
}
if len(a.MakeDepends) != 0 {
makeDeps[0], makeDeps[1], err = pacman.DepSatisfier(q[0].Depends)
fmt.Println("\x1b[1;32m=>\x1b[1;33m Make Dependencies: \x1b[0m")
printDeps(makeDeps[0], makeDeps[1])
makeDeps[0], makeDeps[1] = depSearch(q[0].MakeDepends, false, false)
if len(makeDeps[0]) != 0 || len(makeDeps[1]) != 0 {
fmt.Println("\x1b[1;32m=>\x1b[1;33m Make Dependencies: \x1b[0m")
printDeps(makeDeps[0], makeDeps[1])
}
}
depSearch(a.MakeDepends, false, true)
err = nil
return
}

View file

@ -240,6 +240,46 @@ func PackageSlices(toCheck []string) (aur []string, repo []string, err error) {
return
}
// BuildDependencies finds packages, on the second run
// compares with a baselist and avoids searching those
func BuildDependencies(baselist []string) func(toCheck []string, isBaseList bool, last bool) (repo []string, notFound []string) {
h, _ := conf.CreateHandle()
localDb, _ := h.LocalDb()
dbList, _ := h.SyncDbs()
f := func(c rune) bool {
return c == '>' || c == '<' || c == '=' || c == ' '
}
return func(toCheck []string, isBaseList bool, close bool) (repo []string, notFound []string) {
if close {
h.Release()
return
}
Loop:
for _, dep := range toCheck {
if !isBaseList {
for _, base := range baselist {
if base == dep {
continue Loop
}
}
}
if _, erp := localDb.PkgCache().FindSatisfier(dep); erp == nil {
continue
} else if pkg, erp := dbList.FindSatisfier(dep); erp == nil {
repo = append(repo, pkg.Name())
} else {
field := strings.FieldsFunc(dep, f)
notFound = append(notFound, field[0])
}
}
return
}
}
// DepSatisfier receives a string slice, returns a slice of packages found in
// repos and one of packages not found in repos. Leaves out installed packages.
func DepSatisfier(toCheck []string) (repo []string, notFound []string, err error) {
@ -277,81 +317,6 @@ func DepSatisfier(toCheck []string) (repo []string, notFound []string, err error
return
}
// OutofRepo returns a list of packages not installed and not resolvable
// Accepts inputs like 'gtk2', 'java-environment=8', 'linux >= 4.20'
func OutofRepo(toCheck []string) (aur []string, repo []string, err error) {
h, err := conf.CreateHandle()
defer h.Release()
if err != nil {
return
}
localDb, err := h.LocalDb()
if err != nil {
return
}
dbList, err := h.SyncDbs()
if err != nil {
return
}
f := func(c rune) bool {
return c == '>' || c == '<' || c == '=' || c == ' '
}
toCheckLoop:
for _, dep := range toCheck {
field := strings.FieldsFunc(dep, f)
for _, checkR := range repo {
if field[0] == checkR {
continue toCheckLoop
}
}
for _, checkA := range aur {
if field[0] == checkA {
continue toCheckLoop
}
}
// Check if dep is installed
_, err = localDb.PkgByName(field[0])
if err == nil {
continue
}
found := false
Loop:
for _, db := range dbList.Slice() {
// First, Check if they're provided by package name.
_, err = db.PkgByName(field[0])
if err == nil {
found = true
repo = append(repo, field[0])
break Loop
}
for _, pkg := range db.PkgCache().Slice() {
for _, p := range pkg.Provides().Slice() {
if p.String() == dep {
found = true
repo = append(repo, pkg.Name())
break Loop
}
}
}
}
if !found {
aur = append(aur, field[0])
}
}
err = nil
return
}
// Install sends an install command to pacman with the pkgName slice
func Install(pkgName []string, flags []string) (err error) {
if len(pkgName) == 0 {