mirror of
https://github.com/mudler/luet.git
synced 2025-08-29 04:10:54 +00:00
Add Bigger/Lower to Package to allow version comparison easier
This commit is contained in:
parent
69be9a2dd1
commit
adcd8df49e
@ -57,6 +57,7 @@ type Package interface {
|
|||||||
GetVersion() string
|
GetVersion() string
|
||||||
RequiresContains(PackageDatabase, Package) (bool, error)
|
RequiresContains(PackageDatabase, Package) (bool, error)
|
||||||
Matches(m Package) bool
|
Matches(m Package) bool
|
||||||
|
Bigger(m Package) bool
|
||||||
|
|
||||||
AddUse(use string)
|
AddUse(use string)
|
||||||
RemoveUse(use string)
|
RemoveUse(use string)
|
||||||
@ -254,13 +255,19 @@ func (p *DefaultPackage) Clone() Package {
|
|||||||
copier.Copy(&new, &p)
|
copier.Copy(&new, &p)
|
||||||
return new
|
return new
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *DefaultPackage) Matches(m Package) bool {
|
func (p *DefaultPackage) Matches(m Package) bool {
|
||||||
if p.GetFingerPrint() == m.GetFingerPrint() {
|
if p.GetFingerPrint() == m.GetFingerPrint() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
func (p *DefaultPackage) Bigger(m Package) bool {
|
||||||
|
low := Lower([]Package{p, m})
|
||||||
|
if low.Matches(m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (p *DefaultPackage) Expand(definitiondb PackageDatabase) ([]Package, error) {
|
func (p *DefaultPackage) Expand(definitiondb PackageDatabase) ([]Package, error) {
|
||||||
var versionsInWorld []Package
|
var versionsInWorld []Package
|
||||||
@ -332,7 +339,29 @@ func (pack *DefaultPackage) RequiresContains(definitiondb PackageDatabase, s Pac
|
|||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
func Lower(set []Package) Package {
|
||||||
|
var versionsMap map[string]Package = make(map[string]Package)
|
||||||
|
if len(set) == 0 {
|
||||||
|
panic("Best needs a list with elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
versionsRaw := []string{}
|
||||||
|
for _, p := range set {
|
||||||
|
versionsRaw = append(versionsRaw, p.GetVersion())
|
||||||
|
versionsMap[p.GetVersion()] = p
|
||||||
|
}
|
||||||
|
|
||||||
|
versions := make([]*version.Version, len(versionsRaw))
|
||||||
|
for i, raw := range versionsRaw {
|
||||||
|
v, _ := version.NewVersion(raw)
|
||||||
|
versions[i] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// After this, the versions are properly sorted
|
||||||
|
sort.Sort(version.Collection(versions))
|
||||||
|
|
||||||
|
return versionsMap[versions[0].Original()]
|
||||||
|
}
|
||||||
func Best(set []Package) Package {
|
func Best(set []Package) Package {
|
||||||
var versionsMap map[string]Package = make(map[string]Package)
|
var versionsMap map[string]Package = make(map[string]Package)
|
||||||
if len(set) == 0 {
|
if len(set) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user