Add FindPackages()

The version inmemory is optimized, while the boltdb implementation is
not.

It returns a list of the same package but with all the versions present
in the db.
This commit is contained in:
Ettore Di Giacinto
2019-12-06 16:29:15 +01:00
committed by Ettore Di Giacinto
parent 556668fcc4
commit 57181d7cbf
3 changed files with 79 additions and 9 deletions

View File

@@ -22,6 +22,7 @@ import (
"sync"
"time"
version "github.com/hashicorp/go-version"
"github.com/pkg/errors"
storm "github.com/asdine/storm"
@@ -293,3 +294,27 @@ func (db *BoltDatabase) FindPackageCandidate(p Package) (Package, error) {
return required, err
}
// FindPackages return the list of the packages beloging to cat/name (any versions)
// FIXME: Optimize, see inmemorydb
func (db *BoltDatabase) FindPackages(p Package) ([]Package, error) {
var versionsInWorld []Package
for _, w := range db.World() {
if w.GetName() != p.GetName() || w.GetCategory() != p.GetCategory() {
continue
}
v, err := version.NewVersion(w.GetVersion())
if err != nil {
return nil, err
}
constraints, err := version.NewConstraint(p.GetVersion())
if err != nil {
return nil, err
}
if constraints.Check(v) {
versionsInWorld = append(versionsInWorld, w)
}
}
return versionsInWorld, nil
}