From d089ad4931d03370a6a3a8610948cdcc8f5efdeb Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Mon, 15 May 2023 07:41:44 +0000 Subject: [PATCH] feat: return complete repo info --- distro/debian/snapshot/metasnap/metasnap.go | 36 +++++++------------ .../debian/snapshot/metasnap/metasnap_test.go | 6 ++-- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/distro/debian/snapshot/metasnap/metasnap.go b/distro/debian/snapshot/metasnap/metasnap.go index 596c0f5..772c69a 100644 --- a/distro/debian/snapshot/metasnap/metasnap.go +++ b/distro/debian/snapshot/metasnap/metasnap.go @@ -13,17 +13,10 @@ import ( "golang.org/x/time/rate" ) -const apiURL = "http://metasnap.debian.net/cgi-bin/api?" +// Note: Metasnap does not have all the packages, and its API is +// rather buggy. -var archives = []string{ - "debian", - "debian-security", - "debian-backports", - // "debian-archive", - // "debian-debug", - // "debian-ports", - // "debian-volatile", -} +const apiURL = "http://metasnap.debian.net/cgi-bin/api?" var ( limiterTimeout time.Duration = time.Second @@ -100,22 +93,16 @@ type Snapshot struct { Last string } -type PackageInfo struct { +type Repo struct { + Archive string Suite string Component string Snapshot Snapshot } -func GetPackageInfo(pkg, arch, version string) (infos []PackageInfo, err error) { - var result string - - for _, archive := range archives { - result, err = queryAPIf("archive=%s&pkg=%s&arch=%s&ver=%s", - archive, pkg, arch, version) - if err == nil { - break - } - } +func GetRepo(archive, pkg, arch, ver string) (repos []Repo, err error) { + result, err := queryAPIf("archive=%s&pkg=%s&arch=%s&ver=%s", + archive, pkg, arch, ver) if err != nil { return @@ -137,7 +124,8 @@ func GetPackageInfo(pkg, arch, version string) (infos []PackageInfo, err error) return } - info := PackageInfo{ + repo := Repo{ + Archive: archive, Suite: fields[0], Component: fields[1], Snapshot: Snapshot{ @@ -146,10 +134,10 @@ func GetPackageInfo(pkg, arch, version string) (infos []PackageInfo, err error) }, } - infos = append(infos, info) + repos = append(repos, repo) } - if len(infos) == 0 { + if len(repos) == 0 { err = ErrNotFound return } diff --git a/distro/debian/snapshot/metasnap/metasnap_test.go b/distro/debian/snapshot/metasnap/metasnap_test.go index 264a3f4..7705b5a 100644 --- a/distro/debian/snapshot/metasnap/metasnap_test.go +++ b/distro/debian/snapshot/metasnap/metasnap_test.go @@ -6,9 +6,9 @@ import ( "github.com/davecgh/go-spew/spew" ) -func TestGetPackageInfo(t *testing.T) { +func TestGetRepo(t *testing.T) { // existing - infos, err := GetPackageInfo("linux-image-3.8-trunk-amd64", + infos, err := GetRepo("debian", "linux-image-3.8-trunk-amd64", "amd64", "3.8.2-1~experimental.1") if err != nil { t.Fatal(err) @@ -17,7 +17,7 @@ func TestGetPackageInfo(t *testing.T) { t.Log(spew.Sdump(infos)) // non-existing - infos, err = GetPackageInfo("meh", "amd64", "meh") + infos, err = GetRepo("debian", "meh", "amd64", "meh") if err == nil { t.Fatalf("should not be ok, result: %s", spew.Sdump(infos)) }