mirror of
https://github.com/mudler/luet.git
synced 2025-09-01 23:37:07 +00:00
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:
committed by
Ettore Di Giacinto
parent
556668fcc4
commit
57181d7cbf
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user