feat: support matching several architectures
This commit is contained in:
parent
6bb0da5082
commit
fa23cdfc54
@ -68,13 +68,14 @@ type Package struct {
|
||||
}
|
||||
}
|
||||
|
||||
func NewPackage(name, srcname, version, arch string) (p Package, err error) {
|
||||
func NewPackage(name, srcname, version string, archs []string) (
|
||||
p Package, err error) {
|
||||
|
||||
p.Name = name
|
||||
p.Source = srcname
|
||||
p.Version = version
|
||||
p.Arch = arch
|
||||
|
||||
p.Deb.Hash, err = p.getHash()
|
||||
p.Arch, p.Deb.Hash, err = p.getHash(archs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -110,18 +111,21 @@ func NewPackage(name, srcname, version, arch string) (p Package, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (p Package) getHash() (hash string, err error) {
|
||||
func (p Package) getHash(archs []string) (arch, hash string, err error) {
|
||||
binfiles, err := mr.GetBinfiles(p.Name, p.Version)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, res := range binfiles.Result {
|
||||
if res.Architecture == p.Arch {
|
||||
for _, allowedArch := range archs {
|
||||
if res.Architecture == allowedArch {
|
||||
arch = res.Architecture
|
||||
hash = res.Hash
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = errors.New("hash not found")
|
||||
return
|
||||
@ -292,8 +296,8 @@ func filtered(s string, filter []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func Packages(srcname, version, arch, regex string,
|
||||
filter []string) (pkgs []Package, err error) {
|
||||
func Packages(srcname, version, regex string, archs, filter []string) (
|
||||
pkgs []Package, err error) {
|
||||
|
||||
binpkgs, err := mr.GetBinpackages(srcname, version)
|
||||
if err == mr.ErrNotFound {
|
||||
@ -314,7 +318,7 @@ func Packages(srcname, version, arch, regex string,
|
||||
log.Trace().Msgf("matched %v", res.Name)
|
||||
|
||||
var pkg Package
|
||||
pkg, err = NewPackage(res.Name, srcname, version, arch)
|
||||
pkg, err = NewPackage(res.Name, srcname, version, archs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ func TestSourcePackageVersions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPackages(t *testing.T) {
|
||||
packages, err := Packages("linux", "3.16.5-1", "amd64",
|
||||
`^linux-(image|headers)-[0-9\.\-]*-(common|amd64|amd64-unsigned)$`,
|
||||
[]string{})
|
||||
rx := `^linux-(image|headers)-[0-9\.\-]*-(common|amd64|amd64-unsigned)$`
|
||||
packages, err := Packages("linux", "3.16.5-1", rx,
|
||||
[]string{"amd64", "all"}, []string{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user