mirror of
https://github.com/Jguer/yay.git
synced 2025-10-08 00:04:37 -04:00
New dependency parsing method. Halved handle opens
This commit is contained in:
parent
14a1f93d5a
commit
cfb0efea45
19
aur/aur.go
19
aur/aur.go
@ -394,17 +394,24 @@ func (a *Result) Dependencies() (runDeps [2][]string, makeDeps [2][]string, err
|
|||||||
q = append(q, *a)
|
q = append(q, *a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
depSearch := pacman.BuildDependencies(a.Depends)
|
||||||
if len(a.Depends) != 0 {
|
if len(a.Depends) != 0 {
|
||||||
runDeps[0], runDeps[1], err = pacman.DepSatisfier(q[0].Depends)
|
runDeps[0], runDeps[1] = depSearch(q[0].Depends, true, false)
|
||||||
fmt.Println("\x1b[1;32m=>\x1b[1;33m Dependencies: \x1b[0m")
|
if len(runDeps[0]) != 0 || len(runDeps[1]) != 0 {
|
||||||
printDeps(runDeps[0], runDeps[1])
|
fmt.Println("\x1b[1;32m=>\x1b[1;33m Run Dependencies: \x1b[0m")
|
||||||
|
printDeps(runDeps[0], runDeps[1])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(a.MakeDepends) != 0 {
|
if len(a.MakeDepends) != 0 {
|
||||||
makeDeps[0], makeDeps[1], err = pacman.DepSatisfier(q[0].Depends)
|
makeDeps[0], makeDeps[1] = depSearch(q[0].MakeDepends, false, false)
|
||||||
fmt.Println("\x1b[1;32m=>\x1b[1;33m Make Dependencies: \x1b[0m")
|
if len(makeDeps[0]) != 0 || len(makeDeps[1]) != 0 {
|
||||||
printDeps(makeDeps[0], makeDeps[1])
|
fmt.Println("\x1b[1;32m=>\x1b[1;33m Make Dependencies: \x1b[0m")
|
||||||
|
printDeps(makeDeps[0], makeDeps[1])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
depSearch(a.MakeDepends, false, true)
|
||||||
|
|
||||||
err = nil
|
err = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
115
pacman/pacman.go
115
pacman/pacman.go
@ -240,6 +240,46 @@ func PackageSlices(toCheck []string) (aur []string, repo []string, err error) {
|
|||||||
return
|
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
|
// 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.
|
// repos and one of packages not found in repos. Leaves out installed packages.
|
||||||
func DepSatisfier(toCheck []string) (repo []string, notFound []string, err error) {
|
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
|
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
|
// Install sends an install command to pacman with the pkgName slice
|
||||||
func Install(pkgName []string, flags []string) (err error) {
|
func Install(pkgName []string, flags []string) (err error) {
|
||||||
if len(pkgName) == 0 {
|
if len(pkgName) == 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user