From fa23cdfc54e5a9185f893b7f9bbd33ca23e57dbf Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sun, 14 May 2023 11:38:41 +0000 Subject: [PATCH] feat: support matching several architectures --- distro/debian/snapshot/snapshot.go | 24 ++++++++++++++---------- distro/debian/snapshot/snapshot_test.go | 6 +++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/distro/debian/snapshot/snapshot.go b/distro/debian/snapshot/snapshot.go index 58cb4a9..89b3a12 100644 --- a/distro/debian/snapshot/snapshot.go +++ b/distro/debian/snapshot/snapshot.go @@ -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 } diff --git a/distro/debian/snapshot/snapshot_test.go b/distro/debian/snapshot/snapshot_test.go index f5dd3c9..0686064 100644 --- a/distro/debian/snapshot/snapshot_test.go +++ b/distro/debian/snapshot/snapshot_test.go @@ -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) }