1
0

feat: support matching several architectures

This commit is contained in:
dump_stack() 2023-05-14 11:38:41 +00:00
parent 6bb0da5082
commit fa23cdfc54
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 17 additions and 13 deletions

View File

@ -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,16 +111,19 @@ 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 {
hash = res.Hash
return
for _, allowedArch := range archs {
if res.Architecture == allowedArch {
arch = res.Architecture
hash = res.Hash
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
}

View File

@ -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)
}