From 6125dd979e86db4b458f7cb5190bb772dd10fb9e Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 3 Apr 2018 01:25:47 +0100 Subject: [PATCH] Fix versioned dep checking Before versioned deps with the same name would be combined into a single version range. For example: `foo>1 foo>3 foo<4 foo<5` would be merged into the range `33 foo<1` but what was not thought about it that a package or packages could provide multiple versions of a provider. Java being example, you could have 8 and 9 provided for at the same time. This then causes a problem when you try to install two packages at once, one requiring `java<8` and the other `java>9` when combined this leads to a range that can not be satisfied. Instead we now never merge dependencies but check them all individually. We also make sure to pull in all already installed providers. The reason for this is, before if a package did not apear in the dep tree we assumed it to be satisfied because of the .FindSatisfier in the dep resolving. So if you installed a package that needs `foo=1` and you already had a package providing that it would not be in the dep tree and we assume it is fine. But if you install a package that needs `foo=1` and install a package that prvoides `foo=2` then foo will all of a sudden be in the dep tree but only version 2 will be there. For this reason we also load all the already installed packages in so that the `foo=1` will be there. --- dependencies.go | 33 ++++++++++++++++++++++++++++----- install.go | 1 - 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/dependencies.go b/dependencies.go index 8e180e40..3e35cf33 100644 --- a/dependencies.go +++ b/dependencies.go @@ -543,15 +543,23 @@ func depTreeRecursive(dt *depTree, localDb *alpm.Db, syncDb alpm.DbList, isMake } func checkVersions(dt *depTree) error { - depStrings := make([]string, 0) has := make(map[string][]string) + allDeps := make([]*gopkg.Dependency, 0) + + localDb, err := alpmHandle.LocalDb() + if err != nil { + return err + } for _, pkg := range dt.Aur { for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} { for _, dep := range deps { _, _dep := splitNameFromDep(dep) if _dep != "" { - depStrings = append(depStrings, dep) + deps, _ := gopkg.ParseDeps([]string{dep}) + if deps[0] != nil { + allDeps = append(allDeps, deps[0]) + } } } } @@ -573,7 +581,10 @@ func checkVersions(dt *depTree) error { for _, pkg := range dt.Repo { pkg.Depends().ForEach(func(dep alpm.Depend) error { if dep.Mod != alpm.DepModAny { - depStrings = append(depStrings, dep.String()) + deps, _ := gopkg.ParseDeps([]string{dep.String()}) + if deps[0] != nil { + allDeps = append(allDeps, deps[0]) + } } return nil }) @@ -592,9 +603,21 @@ func checkVersions(dt *depTree) error { } - deps, _ := gopkg.ParseDeps(depStrings) + localDb.PkgCache().ForEach(func(pkg alpm.Package) error { + pkg.Provides().ForEach(func(dep alpm.Depend) error { + if dep.Mod != alpm.DepModAny { + addMapStringSlice(has, dep.Name, dep.Version) + } else { + delete(has, dep.Name) + } - for _, dep := range deps { + return nil + }) + + return nil + }) + + for _, dep := range allDeps { satisfied := false verStrs, ok := has[dep.Name] if !ok { diff --git a/install.go b/install.go index 53dabe1a..e01d225f 100644 --- a/install.go +++ b/install.go @@ -72,7 +72,6 @@ func install(parser *arguments) error { parser.targets.set(name) } - requestTargets = parser.targets.toSlice() if len(dt.Missing) > 0 {