Check versioned deps during the dep fetching process

Check versioned deps such as `foo>1` `foo=2` `foo<3`
This commit is contained in:
morganamilo 2018-03-15 13:51:37 +00:00
parent 47bb527a1b
commit 69a86c6a78
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 76 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import (
alpm "github.com/jguer/go-alpm"
rpc "github.com/mikkeloscar/aur"
gopkg "github.com/mikkeloscar/gopkgbuild"
)
type depTree struct {
@ -309,6 +310,13 @@ func getDepTree(pkgs []string) (*depTree, error) {
}
err = depTreeRecursive(dt, localDb, syncDb, false)
if err != nil {
return dt, err
}
if !cmdArgs.existsArg("d", "nodeps") {
err = checkVersions(dt)
}
return dt, err
}
@ -445,3 +453,64 @@ func depTreeRecursive(dt *depTree, localDb *alpm.Db, syncDb alpm.DbList, isMake
return
}
func checkVersions(dt *depTree) error {
depStrings := make([]string, 0)
has := make(map[string]string)
for _, pkg := range dt.Aur {
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
for _, dep := range deps {
depStrings = append(depStrings, dep)
}
}
has[pkg.Name] = pkg.Version
for _, name := range pkg.Provides {
_name, _ver := splitNameFromDep(name)
if _ver != "" {
has[_name] = _ver
}
}
}
for _, pkg := range dt.Repo {
pkg.Depends().ForEach(func(dep alpm.Depend) error {
if dep.Mod != alpm.DepModAny {
has[dep.Name] = dep.Version
}
return nil
})
has[pkg.Name()] = pkg.Version()
pkg.Provides().ForEach(func(dep alpm.Depend) error {
if dep.Mod != alpm.DepModAny {
has[dep.Name] = dep.Version
}
return nil
})
}
deps, _ := gopkg.ParseDeps(depStrings)
for _, dep := range deps {
verStr, ok := has[dep.Name]
if !ok {
continue
}
version, err := gopkg.NewCompleteVersion(verStr)
if err != nil {
return err
}
if !version.Satisfies(dep) {
dt.Missing.set(dep.String())
}
}
return nil
}

View file

@ -55,8 +55,13 @@ func install(parser *arguments) error {
//only error if direct targets or deps are missing
for missingName := range dt.Missing {
if !remoteNamesCache.get(missingName) {
return fmt.Errorf(bold(red(arrow+" Error: ")) +
"Could not find all required package")
str := bold(red(arrow+" Error: ")) + "Could not find all required packages:"
for name := range dt.Missing {
str += "\n\t" + name
}
return fmt.Errorf("%s", str)
}
}