2020-07-10 02:36:45 +02:00
|
|
|
package dep
|
2018-10-11 19:55:23 +02:00
|
|
|
|
|
|
|
import (
|
2022-02-05 14:25:59 +01:00
|
|
|
"errors"
|
2018-10-11 19:55:23 +02:00
|
|
|
"fmt"
|
2018-11-14 13:14:41 +01:00
|
|
|
"os"
|
2018-10-11 19:55:23 +02:00
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
2020-05-02 16:17:20 +02:00
|
|
|
|
2021-09-08 22:28:08 +02:00
|
|
|
"github.com/Jguer/yay/v11/pkg/stringset"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/text"
|
2018-10-11 19:55:23 +02:00
|
|
|
)
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (dp *Pool) checkInnerConflict(name, conflict string, conflicts stringset.MapStringSet) {
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, pkg := range dp.Aur {
|
|
|
|
if pkg.Name == name {
|
|
|
|
continue
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
if satisfiesAur(conflict, pkg) {
|
|
|
|
conflicts.Add(name, pkg.Name)
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, pkg := range dp.Repo {
|
|
|
|
if pkg.Name() == name {
|
|
|
|
continue
|
|
|
|
}
|
2018-10-11 19:55:23 +02:00
|
|
|
|
2020-07-29 01:53:25 +02:00
|
|
|
if satisfiesRepo(conflict, pkg, dp.AlpmExecutor) {
|
2019-01-15 19:41:38 +01:00
|
|
|
conflicts.Add(name, pkg.Name())
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (dp *Pool) checkForwardConflict(name, conflict string, conflicts stringset.MapStringSet) {
|
2020-07-29 01:53:25 +02:00
|
|
|
for _, pkg := range dp.AlpmExecutor.LocalPackages() {
|
2019-01-15 19:41:38 +01:00
|
|
|
if pkg.Name() == name || dp.hasPackage(pkg.Name()) {
|
2020-07-29 01:53:25 +02:00
|
|
|
continue
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
|
2020-07-29 01:53:25 +02:00
|
|
|
if satisfiesRepo(conflict, pkg, dp.AlpmExecutor) {
|
2018-10-11 19:55:23 +02:00
|
|
|
n := pkg.Name()
|
2019-01-15 19:41:38 +01:00
|
|
|
if n != conflict {
|
|
|
|
n += " (" + conflict + ")"
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-10-11 19:55:23 +02:00
|
|
|
conflicts.Add(name, n)
|
|
|
|
}
|
2020-07-29 01:53:25 +02:00
|
|
|
}
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (dp *Pool) checkReverseConflict(name, conflict string, conflicts stringset.MapStringSet) {
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, pkg := range dp.Aur {
|
|
|
|
if pkg.Name == name {
|
|
|
|
continue
|
|
|
|
}
|
2018-10-11 19:55:23 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
if satisfiesAur(conflict, pkg) {
|
|
|
|
if name != conflict {
|
|
|
|
name += " (" + conflict + ")"
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
2019-01-15 19:41:38 +01:00
|
|
|
|
|
|
|
conflicts.Add(pkg.Name, name)
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, pkg := range dp.Repo {
|
2018-10-11 19:55:23 +02:00
|
|
|
if pkg.Name() == name {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-07-29 01:53:25 +02:00
|
|
|
if satisfiesRepo(conflict, pkg, dp.AlpmExecutor) {
|
2019-01-15 19:41:38 +01:00
|
|
|
if name != conflict {
|
|
|
|
name += " (" + conflict + ")"
|
|
|
|
}
|
|
|
|
|
2018-10-11 19:55:23 +02:00
|
|
|
conflicts.Add(pkg.Name(), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (dp *Pool) checkInnerConflicts(conflicts stringset.MapStringSet) {
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, pkg := range dp.Aur {
|
|
|
|
for _, conflict := range pkg.Conflicts {
|
|
|
|
dp.checkInnerConflict(pkg.Name, conflict, conflicts)
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, pkg := range dp.Repo {
|
2020-07-29 01:53:25 +02:00
|
|
|
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
2019-01-15 19:41:38 +01:00
|
|
|
dp.checkInnerConflict(pkg.Name(), conflict.String(), conflicts)
|
2020-07-29 01:53:25 +02:00
|
|
|
}
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (dp *Pool) checkForwardConflicts(conflicts stringset.MapStringSet) {
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, pkg := range dp.Aur {
|
|
|
|
for _, conflict := range pkg.Conflicts {
|
|
|
|
dp.checkForwardConflict(pkg.Name, conflict, conflicts)
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
2018-10-11 19:55:23 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, pkg := range dp.Repo {
|
2020-07-29 01:53:25 +02:00
|
|
|
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
2019-01-15 19:41:38 +01:00
|
|
|
dp.checkForwardConflict(pkg.Name(), conflict.String(), conflicts)
|
2020-07-29 01:53:25 +02:00
|
|
|
}
|
2018-10-12 02:12:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (dp *Pool) checkReverseConflicts(conflicts stringset.MapStringSet) {
|
2020-07-29 01:53:25 +02:00
|
|
|
for _, pkg := range dp.AlpmExecutor.LocalPackages() {
|
2019-01-15 19:41:38 +01:00
|
|
|
if dp.hasPackage(pkg.Name()) {
|
2020-07-29 01:53:25 +02:00
|
|
|
continue
|
2018-10-12 02:12:25 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-07-29 01:53:25 +02:00
|
|
|
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
2019-01-15 19:41:38 +01:00
|
|
|
dp.checkReverseConflict(pkg.Name(), conflict.String(), conflicts)
|
2020-07-29 01:53:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-12 02:12:25 +02:00
|
|
|
}
|
|
|
|
|
2021-03-14 23:39:55 +01:00
|
|
|
func (dp *Pool) CheckConflicts(useAsk, noConfirm, noDeps bool) (stringset.MapStringSet, error) {
|
|
|
|
conflicts := make(stringset.MapStringSet)
|
|
|
|
if noDeps {
|
|
|
|
return conflicts, nil
|
|
|
|
}
|
|
|
|
|
2018-10-11 19:55:23 +02:00
|
|
|
var wg sync.WaitGroup
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2019-10-16 23:25:40 +02:00
|
|
|
innerConflicts := make(stringset.MapStringSet)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
wg.Add(2)
|
2018-10-11 19:55:23 +02:00
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
text.OperationInfoln(gotext.Get("Checking for conflicts..."))
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-10-11 19:55:23 +02:00
|
|
|
go func() {
|
2019-01-15 19:41:38 +01:00
|
|
|
dp.checkForwardConflicts(conflicts)
|
|
|
|
dp.checkReverseConflicts(conflicts)
|
2018-10-11 19:55:23 +02:00
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
text.OperationInfoln(gotext.Get("Checking for inner conflicts..."))
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-10-11 19:55:23 +02:00
|
|
|
go func() {
|
2019-01-15 19:41:38 +01:00
|
|
|
dp.checkInnerConflicts(innerConflicts)
|
2018-10-12 02:12:25 +02:00
|
|
|
wg.Done()
|
|
|
|
}()
|
2018-10-11 19:55:23 +02:00
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
if len(innerConflicts) != 0 {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Errorln(gotext.Get("\nInner conflicts found:"))
|
2018-10-11 19:55:23 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
for name, pkgs := range innerConflicts {
|
2020-07-10 02:36:45 +02:00
|
|
|
str := text.SprintError(name + ":")
|
2019-01-15 19:41:38 +01:00
|
|
|
for pkg := range pkgs {
|
2020-07-10 02:36:45 +02:00
|
|
|
str += " " + text.Cyan(pkg) + ","
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
str = strings.TrimSuffix(str, ",")
|
2018-10-13 02:16:50 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
fmt.Println(str)
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
2018-10-12 02:12:25 +02:00
|
|
|
}
|
2018-10-11 19:55:23 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
if len(conflicts) != 0 {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Errorln(gotext.Get("\nPackage conflicts found:"))
|
2018-10-12 02:12:25 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
for name, pkgs := range conflicts {
|
2020-07-10 02:36:45 +02:00
|
|
|
str := text.SprintError(gotext.Get("Installing %s will remove:", text.Cyan(name)))
|
2019-01-15 19:41:38 +01:00
|
|
|
for pkg := range pkgs {
|
2020-07-10 02:36:45 +02:00
|
|
|
str += " " + text.Cyan(pkg) + ","
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
str = strings.TrimSuffix(str, ",")
|
|
|
|
|
|
|
|
fmt.Println(str)
|
|
|
|
}
|
|
|
|
}
|
2018-10-12 02:12:25 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
// Add the inner conflicts to the conflicts
|
|
|
|
// These are used to decide what to pass --ask to (if set) or don't pass --noconfirm to
|
|
|
|
// As we have no idea what the order is yet we add every inner conflict to the slice
|
|
|
|
for name, pkgs := range innerConflicts {
|
2019-10-16 23:25:40 +02:00
|
|
|
conflicts[name] = make(stringset.StringSet)
|
2019-01-15 19:41:38 +01:00
|
|
|
for pkg := range pkgs {
|
2019-10-16 23:25:40 +02:00
|
|
|
conflicts[pkg] = make(stringset.StringSet)
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(conflicts) > 0 {
|
2020-07-10 02:36:45 +02:00
|
|
|
if !useAsk {
|
|
|
|
if noConfirm {
|
2022-02-05 14:25:59 +01:00
|
|
|
return nil, errors.New(gotext.Get("package conflicts can not be resolved with noconfirm, aborting"))
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Errorln(gotext.Get("Conflicting packages will have to be confirmed manually"))
|
2018-10-11 19:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return conflicts, nil
|
|
|
|
}
|
2019-01-15 19:41:38 +01:00
|
|
|
|
|
|
|
type missing struct {
|
2019-10-16 23:25:40 +02:00
|
|
|
Good stringset.StringSet
|
2019-01-15 19:41:38 +01:00
|
|
|
Missing map[string][][]string
|
|
|
|
}
|
|
|
|
|
2021-03-16 22:54:53 +01:00
|
|
|
func (dp *Pool) _checkMissing(dep string, stack []string, missing *missing, noDeps, noCheckDeps bool) {
|
2019-10-05 19:39:31 +02:00
|
|
|
if missing.Good.Get(dep) {
|
2019-01-15 19:41:38 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if trees, ok := missing.Missing[dep]; ok {
|
|
|
|
for _, tree := range trees {
|
|
|
|
if stringSliceEqual(tree, stack) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
missing.Missing[dep] = append(missing.Missing[dep], stack)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-16 23:07:43 +01:00
|
|
|
if aurPkg := dp.findSatisfierAur(dep); aurPkg != nil {
|
2019-10-05 19:39:31 +02:00
|
|
|
missing.Good.Set(dep)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-03-16 22:54:53 +01:00
|
|
|
combinedDepList := ComputeCombinedDepList(aurPkg, noDeps, noCheckDeps)
|
|
|
|
for _, deps := range combinedDepList {
|
2019-01-15 19:41:38 +01:00
|
|
|
for _, aurDep := range deps {
|
2020-07-29 01:53:25 +02:00
|
|
|
if dp.AlpmExecutor.LocalSatisfierExists(aurDep) {
|
2019-10-05 19:39:31 +02:00
|
|
|
missing.Good.Set(aurDep)
|
2019-01-15 19:41:38 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-03-16 22:54:53 +01:00
|
|
|
dp._checkMissing(aurDep, append(stack, aurPkg.Name), missing, noDeps, noCheckDeps)
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-16 23:07:43 +01:00
|
|
|
if repoPkg := dp.findSatisfierRepo(dep); repoPkg != nil {
|
2019-10-05 19:39:31 +02:00
|
|
|
missing.Good.Set(dep)
|
2021-03-16 22:54:53 +01:00
|
|
|
|
|
|
|
if noDeps {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-29 01:53:25 +02:00
|
|
|
for _, dep := range dp.AlpmExecutor.PackageDepends(repoPkg) {
|
|
|
|
if dp.AlpmExecutor.LocalSatisfierExists(dep.String()) {
|
|
|
|
missing.Good.Set(dep.String())
|
|
|
|
continue
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
|
2021-03-16 22:54:53 +01:00
|
|
|
dp._checkMissing(dep.String(), append(stack, repoPkg.Name()), missing, noDeps, noCheckDeps)
|
2020-07-29 01:53:25 +02:00
|
|
|
}
|
2019-01-15 19:41:38 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
missing.Missing[dep] = [][]string{stack}
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func stringSliceEqual(a, b []string) bool {
|
|
|
|
if a == nil && b == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if a == nil || b == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(a); i++ {
|
|
|
|
if a[i] != b[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-03-16 22:54:53 +01:00
|
|
|
func (dp *Pool) CheckMissing(noDeps, noCheckDeps bool) error {
|
2019-01-15 19:41:38 +01:00
|
|
|
missing := &missing{
|
2019-10-16 23:25:40 +02:00
|
|
|
make(stringset.StringSet),
|
2019-01-15 19:41:38 +01:00
|
|
|
make(map[string][][]string),
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, target := range dp.Targets {
|
2021-03-16 22:54:53 +01:00
|
|
|
dp._checkMissing(target.DepString(), make([]string, 0), missing, noDeps, noCheckDeps)
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(missing.Missing) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Errorln(gotext.Get("Could not find all required packages:"))
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2019-01-15 19:41:38 +01:00
|
|
|
for dep, trees := range missing.Missing {
|
|
|
|
for _, tree := range trees {
|
2020-07-10 02:36:45 +02:00
|
|
|
fmt.Fprintf(os.Stderr, "\t%s", text.Cyan(dep))
|
2019-01-15 19:41:38 +01:00
|
|
|
|
|
|
|
if len(tree) == 0 {
|
2020-05-04 09:24:32 +02:00
|
|
|
fmt.Fprint(os.Stderr, gotext.Get(" (Target"))
|
2019-01-15 19:41:38 +01:00
|
|
|
} else {
|
2020-05-04 09:24:32 +02:00
|
|
|
fmt.Fprint(os.Stderr, gotext.Get(" (Wanted by: "))
|
2019-01-15 19:41:38 +01:00
|
|
|
for n := 0; n < len(tree)-1; n++ {
|
2020-07-10 02:36:45 +02:00
|
|
|
fmt.Fprint(os.Stderr, text.Cyan(tree[n]), " -> ")
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
2020-07-10 02:36:45 +02:00
|
|
|
fmt.Fprint(os.Stderr, text.Cyan(tree[len(tree)-1]))
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
fmt.Fprintln(os.Stderr, ")")
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("")
|
|
|
|
}
|