1
0

Add deb package url and its repo component

This commit is contained in:
dump_stack() 2023-05-11 13:20:36 +00:00
parent 3a29b3b869
commit aaca60cafc
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 28 additions and 5 deletions

View File

@ -2,11 +2,16 @@ package snapshot
import (
"errors"
"fmt"
"net/url"
"regexp"
"strings"
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot/mr"
)
const URL = "https://snapshot.debian.org"
func SourcePackageVersions(name string) (versions []string, err error) {
pkg, err := mr.GetPackage(name)
if err != nil {
@ -24,13 +29,18 @@ type Package struct {
Source string
Version string
Arch string
Binary struct {
Deb struct {
Name string
Hash string
URL string
}
Repo struct {
Snapshot string
Archive string
Component string
}
}
@ -40,21 +50,34 @@ func NewPackage(name, srcname, version, arch string) (p Package, err error) {
p.Version = version
p.Arch = arch
p.Binary.Hash, err = p.getHash()
p.Deb.Hash, err = p.getHash()
if err != nil {
return
}
info, err := mr.GetInfo(p.Binary.Hash)
info, err := mr.GetInfo(p.Deb.Hash)
if err != nil {
return
}
p.Binary.Name = info.Result[0].Name
p.Deb.Name = info.Result[0].Name
p.Repo.Archive = info.Result[0].ArchiveName
p.Repo.Snapshot = info.Result[0].FirstSeen
p.Deb.URL, err = url.JoinPath(URL, "archive", p.Repo.Archive,
p.Repo.Snapshot, info.Result[0].Path, p.Deb.Name)
if err != nil {
return
}
split := strings.Split(info.Result[0].Path, "/")
if split[1] != "pool" || len(split) < 3 {
err = fmt.Errorf("incorrect path: %s", info.Result[0].Path)
return
}
p.Repo.Component = split[2]
return
}

View File

@ -19,7 +19,7 @@ func TestSourcePackageVersions(t *testing.T) {
}
func TestPackages(t *testing.T) {
packages, err := Packages("linux", "6.1.20-2", "amd64",
packages, err := Packages("linux", "3.16.5-1", "amd64",
`^linux-(image|headers)-[0-9\.\-]*-(amd64|amd64-unsigned)$`)
if err != nil {
t.Fatal(err)