mirror of
https://github.com/Jguer/yay.git
synced 2025-12-09 00:03:52 -05:00
feat(db): abstract db ops need for dep
This commit is contained in:
parent
7f4c277ce7
commit
ad9bc9ef8f
@ -1014,7 +1014,7 @@ func buildInstallPkgbuilds(
|
|||||||
for _, pkg := range base {
|
for _, pkg := range base {
|
||||||
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
||||||
for _, dep := range deps {
|
for _, dep := range deps {
|
||||||
if _, errSatisfier := dp.LocalDB.PkgCache().FindSatisfier(dep); errSatisfier != nil {
|
if !dp.AlpmExecutor.LocalSatisfierExists(dep) {
|
||||||
satisfied = false
|
satisfied = false
|
||||||
text.Warnln(gotext.Get("%s not satisfied, flushing install queue", dep))
|
text.Warnln(gotext.Get("%s not satisfied, flushing install queue", dep))
|
||||||
break all
|
break all
|
||||||
@ -1072,9 +1072,7 @@ func buildInstallPkgbuilds(
|
|||||||
if cmdArgs.ExistsArg("needed") {
|
if cmdArgs.ExistsArg("needed") {
|
||||||
installed := true
|
installed := true
|
||||||
for _, split := range base {
|
for _, split := range base {
|
||||||
if alpmpkg := dp.LocalDB.Pkg(split.Name); alpmpkg == nil || alpmpkg.Version() != pkgVersion {
|
installed = dp.AlpmExecutor.IsCorrectVersionInstalled(split.Name, pkgVersion)
|
||||||
installed = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if installed {
|
if installed {
|
||||||
|
|||||||
93
pkg/db/alpm.go
Normal file
93
pkg/db/alpm.go
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
alpm "github.com/Jguer/go-alpm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AlpmExecutor struct {
|
||||||
|
Handle *alpm.Handle
|
||||||
|
LocalDB *alpm.DB
|
||||||
|
SyncDB alpm.DBList
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewExecutor(handle *alpm.Handle) (*AlpmExecutor, error) {
|
||||||
|
localDB, err := handle.LocalDB()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
syncDB, err := handle.SyncDBs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &AlpmExecutor{Handle: handle, LocalDB: localDB, SyncDB: syncDB}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) LocalSatisfierExists(pkgName string) bool {
|
||||||
|
if _, err := ae.LocalDB.PkgCache().FindSatisfier(pkgName); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) IsCorrectVersionInstalled(pkgName, versionRequired string) bool {
|
||||||
|
alpmPackage := ae.LocalDB.Pkg(pkgName)
|
||||||
|
if alpmPackage == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return alpmPackage.Version() == versionRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) SyncSatisfier(pkgName string) RepoPackage {
|
||||||
|
foundPkg, err := ae.SyncDB.FindSatisfier(pkgName)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return foundPkg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) PackagesFromGroup(groupName string) []RepoPackage {
|
||||||
|
groupPackages := []RepoPackage{}
|
||||||
|
_ = ae.SyncDB.FindGroupPkgs(groupName).ForEach(func(pkg alpm.Package) error {
|
||||||
|
groupPackages = append(groupPackages, &pkg)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return groupPackages
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) LocalPackages() []RepoPackage {
|
||||||
|
localPackages := []RepoPackage{}
|
||||||
|
_ = ae.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
|
||||||
|
localPackages = append(localPackages, RepoPackage(&pkg))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return localPackages
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) PackageFromDB(pkgName, dbName string) RepoPackage {
|
||||||
|
singleDB, err := ae.Handle.SyncDBByName(dbName)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
foundPkg, err := singleDB.PkgCache().FindSatisfier(pkgName)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return foundPkg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) PackageDepends(pkg RepoPackage) []alpm.Depend {
|
||||||
|
alpmPackage := pkg.(*alpm.Package)
|
||||||
|
return alpmPackage.Depends().Slice()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) PackageProvides(pkg RepoPackage) []alpm.Depend {
|
||||||
|
alpmPackage := pkg.(*alpm.Package)
|
||||||
|
return alpmPackage.Provides().Slice()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ae *AlpmExecutor) PackageConflicts(pkg RepoPackage) []alpm.Depend {
|
||||||
|
alpmPackage := pkg.(*alpm.Package)
|
||||||
|
return alpmPackage.Conflicts().Slice()
|
||||||
|
}
|
||||||
10
pkg/db/executor.go
Normal file
10
pkg/db/executor.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import alpm "github.com/Jguer/go-alpm"
|
||||||
|
|
||||||
|
type RepoPackage interface {
|
||||||
|
Base() string
|
||||||
|
Name() string
|
||||||
|
Version() string
|
||||||
|
DB() *alpm.DB
|
||||||
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
package dep
|
package dep
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
alpm "github.com/Jguer/go-alpm"
|
alpm "github.com/Jguer/go-alpm"
|
||||||
rpc "github.com/mikkeloscar/aur"
|
rpc "github.com/mikkeloscar/aur"
|
||||||
|
|
||||||
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -121,19 +121,15 @@ func satisfiesAur(dep string, pkg *rpc.Pkg) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func satisfiesRepo(dep string, pkg *alpm.Package) bool {
|
func satisfiesRepo(dep string, pkg db.RepoPackage, ae *db.AlpmExecutor) bool {
|
||||||
if pkgSatisfies(pkg.Name(), pkg.Version(), dep) {
|
if pkgSatisfies(pkg.Name(), pkg.Version(), dep) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if pkg.Provides().ForEach(func(provide alpm.Depend) error {
|
for _, provided := range ae.PackageProvides(pkg) {
|
||||||
if provideSatisfies(provide.String(), dep) {
|
if provideSatisfies(provided.String(), dep) {
|
||||||
return fmt.Errorf("")
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}) != nil {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
alpm "github.com/Jguer/go-alpm"
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
|
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
@ -29,28 +28,26 @@ func (dp *Pool) checkInnerConflict(name, conflict string, conflicts stringset.Ma
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if satisfiesRepo(conflict, pkg) {
|
if satisfiesRepo(conflict, pkg, dp.AlpmExecutor) {
|
||||||
conflicts.Add(name, pkg.Name())
|
conflicts.Add(name, pkg.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *Pool) checkForwardConflict(name, conflict string, conflicts stringset.MapStringSet) {
|
func (dp *Pool) checkForwardConflict(name, conflict string, conflicts stringset.MapStringSet) {
|
||||||
_ = dp.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
|
for _, pkg := range dp.AlpmExecutor.LocalPackages() {
|
||||||
if pkg.Name() == name || dp.hasPackage(pkg.Name()) {
|
if pkg.Name() == name || dp.hasPackage(pkg.Name()) {
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if satisfiesRepo(conflict, &pkg) {
|
if satisfiesRepo(conflict, pkg, dp.AlpmExecutor) {
|
||||||
n := pkg.Name()
|
n := pkg.Name()
|
||||||
if n != conflict {
|
if n != conflict {
|
||||||
n += " (" + conflict + ")"
|
n += " (" + conflict + ")"
|
||||||
}
|
}
|
||||||
conflicts.Add(name, n)
|
conflicts.Add(name, n)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *Pool) checkReverseConflict(name, conflict string, conflicts stringset.MapStringSet) {
|
func (dp *Pool) checkReverseConflict(name, conflict string, conflicts stringset.MapStringSet) {
|
||||||
@ -73,7 +70,7 @@ func (dp *Pool) checkReverseConflict(name, conflict string, conflicts stringset.
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if satisfiesRepo(conflict, pkg) {
|
if satisfiesRepo(conflict, pkg, dp.AlpmExecutor) {
|
||||||
if name != conflict {
|
if name != conflict {
|
||||||
name += " (" + conflict + ")"
|
name += " (" + conflict + ")"
|
||||||
}
|
}
|
||||||
@ -91,10 +88,9 @@ func (dp *Pool) checkInnerConflicts(conflicts stringset.MapStringSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pkg := range dp.Repo {
|
for _, pkg := range dp.Repo {
|
||||||
_ = pkg.Conflicts().ForEach(func(conflict alpm.Depend) error {
|
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
||||||
dp.checkInnerConflict(pkg.Name(), conflict.String(), conflicts)
|
dp.checkInnerConflict(pkg.Name(), conflict.String(), conflicts)
|
||||||
return nil
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,26 +102,21 @@ func (dp *Pool) checkForwardConflicts(conflicts stringset.MapStringSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pkg := range dp.Repo {
|
for _, pkg := range dp.Repo {
|
||||||
_ = pkg.Conflicts().ForEach(func(conflict alpm.Depend) error {
|
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
||||||
dp.checkForwardConflict(pkg.Name(), conflict.String(), conflicts)
|
dp.checkForwardConflict(pkg.Name(), conflict.String(), conflicts)
|
||||||
return nil
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *Pool) checkReverseConflicts(conflicts stringset.MapStringSet) {
|
func (dp *Pool) checkReverseConflicts(conflicts stringset.MapStringSet) {
|
||||||
_ = dp.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
|
for _, pkg := range dp.AlpmExecutor.LocalPackages() {
|
||||||
if dp.hasPackage(pkg.Name()) {
|
if dp.hasPackage(pkg.Name()) {
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
|
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
||||||
_ = pkg.Conflicts().ForEach(func(conflict alpm.Depend) error {
|
|
||||||
dp.checkReverseConflict(pkg.Name(), conflict.String(), conflicts)
|
dp.checkReverseConflict(pkg.Name(), conflict.String(), conflicts)
|
||||||
return nil
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *Pool) CheckConflicts(useAsk, noConfirm bool) (stringset.MapStringSet, error) {
|
func (dp *Pool) CheckConflicts(useAsk, noConfirm bool) (stringset.MapStringSet, error) {
|
||||||
@ -225,7 +216,7 @@ func (dp *Pool) _checkMissing(dep string, stack []string, missing *missing) {
|
|||||||
missing.Good.Set(dep)
|
missing.Good.Set(dep)
|
||||||
for _, deps := range [3][]string{aurPkg.Depends, aurPkg.MakeDepends, aurPkg.CheckDepends} {
|
for _, deps := range [3][]string{aurPkg.Depends, aurPkg.MakeDepends, aurPkg.CheckDepends} {
|
||||||
for _, aurDep := range deps {
|
for _, aurDep := range deps {
|
||||||
if _, err := dp.LocalDB.PkgCache().FindSatisfier(aurDep); err == nil {
|
if dp.AlpmExecutor.LocalSatisfierExists(aurDep) {
|
||||||
missing.Good.Set(aurDep)
|
missing.Good.Set(aurDep)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -240,15 +231,14 @@ func (dp *Pool) _checkMissing(dep string, stack []string, missing *missing) {
|
|||||||
repoPkg := dp.findSatisfierRepo(dep)
|
repoPkg := dp.findSatisfierRepo(dep)
|
||||||
if repoPkg != nil {
|
if repoPkg != nil {
|
||||||
missing.Good.Set(dep)
|
missing.Good.Set(dep)
|
||||||
_ = repoPkg.Depends().ForEach(func(repoDep alpm.Depend) error {
|
for _, dep := range dp.AlpmExecutor.PackageDepends(repoPkg) {
|
||||||
if _, err := dp.LocalDB.PkgCache().FindSatisfier(repoDep.String()); err == nil {
|
if dp.AlpmExecutor.LocalSatisfierExists(dep.String()) {
|
||||||
missing.Good.Set(repoDep.String())
|
missing.Good.Set(dep.String())
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
dp._checkMissing(repoDep.String(), append(stack, repoPkg.Name()), missing)
|
dp._checkMissing(dep.String(), append(stack, repoPkg.Name()), missing)
|
||||||
return nil
|
}
|
||||||
})
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,23 +3,23 @@ package dep
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
alpm "github.com/Jguer/go-alpm"
|
|
||||||
rpc "github.com/mikkeloscar/aur"
|
rpc "github.com/mikkeloscar/aur"
|
||||||
|
|
||||||
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Order struct {
|
type Order struct {
|
||||||
Aur []Base
|
Aur []Base
|
||||||
Repo []*alpm.Package
|
Repo []db.RepoPackage
|
||||||
Runtime stringset.StringSet
|
Runtime stringset.StringSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeOrder() *Order {
|
func makeOrder() *Order {
|
||||||
return &Order{
|
return &Order{
|
||||||
make([]Base, 0),
|
make([]Base, 0),
|
||||||
make([]*alpm.Package, 0),
|
make([]db.RepoPackage, 0),
|
||||||
make(stringset.StringSet),
|
make(stringset.StringSet),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,20 +78,18 @@ func (do *Order) orderPkgAur(pkg *rpc.Pkg, dp *Pool, runtime bool) {
|
|||||||
do.Aur = append(do.Aur, Base{pkg})
|
do.Aur = append(do.Aur, Base{pkg})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (do *Order) orderPkgRepo(pkg *alpm.Package, dp *Pool, runtime bool) {
|
func (do *Order) orderPkgRepo(pkg db.RepoPackage, dp *Pool, runtime bool) {
|
||||||
if runtime {
|
if runtime {
|
||||||
do.Runtime.Set(pkg.Name())
|
do.Runtime.Set(pkg.Name())
|
||||||
}
|
}
|
||||||
delete(dp.Repo, pkg.Name())
|
delete(dp.Repo, pkg.Name())
|
||||||
|
|
||||||
_ = pkg.Depends().ForEach(func(dep alpm.Depend) (err error) {
|
for _, dep := range dp.AlpmExecutor.PackageDepends(pkg) {
|
||||||
repoPkg := dp.findSatisfierRepo(dep.String())
|
repoPkg := dp.findSatisfierRepo(dep.String())
|
||||||
if repoPkg != nil {
|
if repoPkg != nil {
|
||||||
do.orderPkgRepo(repoPkg, dp, runtime)
|
do.orderPkgRepo(repoPkg, dp, runtime)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
do.Repo = append(do.Repo, pkg)
|
do.Repo = append(do.Repo, pkg)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
rpc "github.com/mikkeloscar/aur"
|
rpc "github.com/mikkeloscar/aur"
|
||||||
|
|
||||||
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/query"
|
"github.com/Jguer/yay/v10/pkg/query"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
@ -27,11 +28,11 @@ type Target struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ToTarget(pkg string) Target {
|
func ToTarget(pkg string) Target {
|
||||||
db, dep := text.SplitDBFromName(pkg)
|
dbName, depString := text.SplitDBFromName(pkg)
|
||||||
name, mod, depVersion := splitDep(dep)
|
name, mod, depVersion := splitDep(depString)
|
||||||
|
|
||||||
return Target{
|
return Target{
|
||||||
DB: db,
|
DB: dbName,
|
||||||
Name: name,
|
Name: name,
|
||||||
Mod: mod,
|
Mod: mod,
|
||||||
Version: depVersion,
|
Version: depVersion,
|
||||||
@ -51,44 +52,34 @@ func (t Target) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Pool struct {
|
type Pool struct {
|
||||||
Targets []Target
|
Targets []Target
|
||||||
Explicit stringset.StringSet
|
Explicit stringset.StringSet
|
||||||
Repo map[string]*alpm.Package
|
Repo map[string]db.RepoPackage
|
||||||
Aur map[string]*rpc.Pkg
|
Aur map[string]*rpc.Pkg
|
||||||
AurCache map[string]*rpc.Pkg
|
AurCache map[string]*rpc.Pkg
|
||||||
Groups []string
|
Groups []string
|
||||||
LocalDB *alpm.DB
|
AlpmExecutor *db.AlpmExecutor
|
||||||
SyncDB alpm.DBList
|
Warnings *query.AURWarnings
|
||||||
Warnings *query.AURWarnings
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func makePool(alpmHandle *alpm.Handle) (*Pool, error) {
|
func makePool(alpmHandle *alpm.Handle) *Pool {
|
||||||
localDB, err := alpmHandle.LocalDB()
|
ae, _ := db.NewExecutor(alpmHandle)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
syncDB, err := alpmHandle.SyncDBs()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
dp := &Pool{
|
dp := &Pool{
|
||||||
make([]Target, 0),
|
make([]Target, 0),
|
||||||
make(stringset.StringSet),
|
make(stringset.StringSet),
|
||||||
make(map[string]*alpm.Package),
|
make(map[string]db.RepoPackage),
|
||||||
make(map[string]*rpc.Pkg),
|
make(map[string]*rpc.Pkg),
|
||||||
make(map[string]*rpc.Pkg),
|
make(map[string]*rpc.Pkg),
|
||||||
make([]string, 0),
|
make([]string, 0),
|
||||||
localDB,
|
ae,
|
||||||
syncDB,
|
|
||||||
nil,
|
nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
return dp, nil
|
return dp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Includes db/ prefixes and group installs
|
// Includes db/ prefixes and group installs
|
||||||
func (dp *Pool) ResolveTargets(pkgs []string, alpmHandle *alpm.Handle,
|
func (dp *Pool) ResolveTargets(pkgs []string,
|
||||||
mode settings.TargetMode,
|
mode settings.TargetMode,
|
||||||
ignoreProviders, noConfirm, provides bool, rebuild string, splitN int) error {
|
ignoreProviders, noConfirm, provides bool, rebuild string, splitN int) error {
|
||||||
// RPC requests are slow
|
// RPC requests are slow
|
||||||
@ -99,7 +90,6 @@ func (dp *Pool) ResolveTargets(pkgs []string, alpmHandle *alpm.Handle,
|
|||||||
pkgs = query.RemoveInvalidTargets(pkgs, mode)
|
pkgs = query.RemoveInvalidTargets(pkgs, mode)
|
||||||
|
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
var err error
|
|
||||||
target := ToTarget(pkg)
|
target := ToTarget(pkg)
|
||||||
|
|
||||||
// skip targets already satisfied
|
// skip targets already satisfied
|
||||||
@ -111,8 +101,7 @@ func (dp *Pool) ResolveTargets(pkgs []string, alpmHandle *alpm.Handle,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var foundPkg *alpm.Package
|
var foundPkg db.RepoPackage
|
||||||
var singleDB *alpm.DB
|
|
||||||
|
|
||||||
// aur/ prefix means we only check the aur
|
// aur/ prefix means we only check the aur
|
||||||
if target.DB == "aur" || mode == settings.ModeAUR {
|
if target.DB == "aur" || mode == settings.ModeAUR {
|
||||||
@ -121,19 +110,15 @@ func (dp *Pool) ResolveTargets(pkgs []string, alpmHandle *alpm.Handle,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there'ss a different priefix only look in that repo
|
// If there'ss a different prefix only look in that repo
|
||||||
if target.DB != "" {
|
if target.DB != "" {
|
||||||
singleDB, err = alpmHandle.SyncDBByName(target.DB)
|
foundPkg = dp.AlpmExecutor.PackageFromDB(target.DepString(), target.DB)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
foundPkg, err = singleDB.PkgCache().FindSatisfier(target.DepString())
|
|
||||||
// otherwise find it in any repo
|
|
||||||
} else {
|
} else {
|
||||||
foundPkg, err = dp.SyncDB.FindSatisfier(target.DepString())
|
// otherwise find it in any repo
|
||||||
|
foundPkg = dp.AlpmExecutor.SyncSatisfier(target.DepString())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if foundPkg != nil {
|
||||||
dp.Targets = append(dp.Targets, target)
|
dp.Targets = append(dp.Targets, target)
|
||||||
dp.Explicit.Set(foundPkg.Name())
|
dp.Explicit.Set(foundPkg.Name())
|
||||||
dp.ResolveRepoDependency(foundPkg)
|
dp.ResolveRepoDependency(foundPkg)
|
||||||
@ -146,13 +131,12 @@ func (dp *Pool) ResolveTargets(pkgs []string, alpmHandle *alpm.Handle,
|
|||||||
// the user specified a db but there's no easy way to do
|
// the user specified a db but there's no easy way to do
|
||||||
// it without making alpm_lists so don't bother for now
|
// it without making alpm_lists so don't bother for now
|
||||||
// db/group is probably a rare use case
|
// db/group is probably a rare use case
|
||||||
group := dp.SyncDB.FindGroupPkgs(target.Name)
|
groupPackages := dp.AlpmExecutor.PackagesFromGroup(target.Name)
|
||||||
if !group.Empty() {
|
if len(groupPackages) > 0 {
|
||||||
dp.Groups = append(dp.Groups, target.String())
|
dp.Groups = append(dp.Groups, target.String())
|
||||||
_ = group.ForEach(func(pkg alpm.Package) error {
|
for _, pkg := range groupPackages {
|
||||||
dp.Explicit.Set(pkg.Name())
|
dp.Explicit.Set(pkg.Name())
|
||||||
return nil
|
}
|
||||||
})
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,7 +203,7 @@ func (dp *Pool) findProvides(pkgs stringset.StringSet) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for pkg := range pkgs {
|
for pkg := range pkgs {
|
||||||
if dp.LocalDB.Pkg(pkg) != nil {
|
if dp.AlpmExecutor.LocalSatisfierExists(pkg) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@ -319,16 +303,16 @@ func (dp *Pool) resolveAURPackages(pkgs stringset.StringSet,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, isInstalled := dp.LocalDB.PkgCache().FindSatisfier(dep) // has satisfier installed: skip
|
isInstalled := dp.AlpmExecutor.LocalSatisfierExists(dep)
|
||||||
hm := settings.HideMenus
|
hm := settings.HideMenus
|
||||||
settings.HideMenus = isInstalled == nil
|
settings.HideMenus = isInstalled
|
||||||
repoPkg, inRepos := dp.SyncDB.FindSatisfier(dep) // has satisfier in repo: fetch it
|
repoPkg := dp.AlpmExecutor.SyncSatisfier(dep) // has satisfier in repo: fetch it
|
||||||
settings.HideMenus = hm
|
settings.HideMenus = hm
|
||||||
if isInstalled == nil && (rebuild != "tree" || inRepos == nil) {
|
if isInstalled && (rebuild != "tree" || repoPkg != nil) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if inRepos == nil {
|
if repoPkg != nil {
|
||||||
dp.ResolveRepoDependency(repoPkg)
|
dp.ResolveRepoDependency(repoPkg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -342,31 +326,25 @@ func (dp *Pool) resolveAURPackages(pkgs stringset.StringSet,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *Pool) ResolveRepoDependency(pkg *alpm.Package) {
|
func (dp *Pool) ResolveRepoDependency(pkg db.RepoPackage) {
|
||||||
dp.Repo[pkg.Name()] = pkg
|
dp.Repo[pkg.Name()] = pkg
|
||||||
|
|
||||||
_ = pkg.Depends().ForEach(func(dep alpm.Depend) (err error) {
|
for _, dep := range dp.AlpmExecutor.PackageDepends(pkg) {
|
||||||
// have satisfier in dep tree: skip
|
|
||||||
if dp.hasSatisfier(dep.String()) {
|
if dp.hasSatisfier(dep.String()) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// has satisfier installed: skip
|
// has satisfier installed: skip
|
||||||
_, isInstalled := dp.LocalDB.PkgCache().FindSatisfier(dep.String())
|
if dp.AlpmExecutor.LocalSatisfierExists(dep.String()) {
|
||||||
if isInstalled == nil {
|
continue
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// has satisfier in repo: fetch it
|
// has satisfier in repo: fetch it
|
||||||
repoPkg, inRepos := dp.SyncDB.FindSatisfier(dep.String())
|
repoPkg := dp.AlpmExecutor.SyncSatisfier(dep.String())
|
||||||
if inRepos != nil {
|
if repoPkg != nil {
|
||||||
return
|
dp.ResolveRepoDependency(repoPkg)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
dp.ResolveRepoDependency(repoPkg)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPool(pkgs []string,
|
func GetPool(pkgs []string,
|
||||||
@ -375,13 +353,10 @@ func GetPool(pkgs []string,
|
|||||||
mode settings.TargetMode,
|
mode settings.TargetMode,
|
||||||
ignoreProviders, noConfirm, provides bool,
|
ignoreProviders, noConfirm, provides bool,
|
||||||
rebuild string, splitN int) (*Pool, error) {
|
rebuild string, splitN int) (*Pool, error) {
|
||||||
dp, err := makePool(alpmHandle)
|
dp := makePool(alpmHandle)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
dp.Warnings = warnings
|
dp.Warnings = warnings
|
||||||
err = dp.ResolveTargets(pkgs, alpmHandle, mode, ignoreProviders, noConfirm, provides, rebuild, splitN)
|
err := dp.ResolveTargets(pkgs, mode, ignoreProviders, noConfirm, provides, rebuild, splitN)
|
||||||
|
|
||||||
return dp, err
|
return dp, err
|
||||||
}
|
}
|
||||||
@ -411,7 +386,7 @@ func (dp *Pool) findSatisfierAurCache(dep string, ignoreProviders, noConfirm, pr
|
|||||||
seen := make(stringset.StringSet)
|
seen := make(stringset.StringSet)
|
||||||
providerSlice := makeProviders(depName)
|
providerSlice := makeProviders(depName)
|
||||||
|
|
||||||
if dp.LocalDB.Pkg(depName) != nil {
|
if dp.AlpmExecutor.LocalSatisfierExists(depName) {
|
||||||
if pkg, ok := dp.AurCache[dep]; ok && pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
if pkg, ok := dp.AurCache[dep]; ok && pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
||||||
return pkg
|
return pkg
|
||||||
}
|
}
|
||||||
@ -465,9 +440,9 @@ func (dp *Pool) findSatisfierAurCache(dep string, ignoreProviders, noConfirm, pr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *Pool) findSatisfierRepo(dep string) *alpm.Package {
|
func (dp *Pool) findSatisfierRepo(dep string) db.RepoPackage {
|
||||||
for _, pkg := range dp.Repo {
|
for _, pkg := range dp.Repo {
|
||||||
if satisfiesRepo(dep, pkg) {
|
if satisfiesRepo(dep, pkg, dp.AlpmExecutor) {
|
||||||
return pkg
|
return pkg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user