Add deb package url and its repo component
This commit is contained in:
		| @@ -2,11 +2,16 @@ package snapshot | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
|  | 	"fmt" | ||||||
|  | 	"net/url" | ||||||
| 	"regexp" | 	"regexp" | ||||||
|  | 	"strings" | ||||||
|  |  | ||||||
| 	"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot/mr" | 	"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) { | func SourcePackageVersions(name string) (versions []string, err error) { | ||||||
| 	pkg, err := mr.GetPackage(name) | 	pkg, err := mr.GetPackage(name) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -24,13 +29,18 @@ type Package struct { | |||||||
| 	Source  string | 	Source  string | ||||||
| 	Version string | 	Version string | ||||||
| 	Arch    string | 	Arch    string | ||||||
| 	Binary  struct { |  | ||||||
|  | 	Deb struct { | ||||||
| 		Name string | 		Name string | ||||||
| 		Hash string | 		Hash string | ||||||
|  | 		URL  string | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	Repo struct { | 	Repo struct { | ||||||
| 		Snapshot string | 		Snapshot string | ||||||
| 		Archive  string | 		Archive  string | ||||||
|  |  | ||||||
|  | 		Component string | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -40,21 +50,34 @@ func NewPackage(name, srcname, version, arch string) (p Package, err error) { | |||||||
| 	p.Version = version | 	p.Version = version | ||||||
| 	p.Arch = arch | 	p.Arch = arch | ||||||
|  |  | ||||||
| 	p.Binary.Hash, err = p.getHash() | 	p.Deb.Hash, err = p.getHash() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	info, err := mr.GetInfo(p.Binary.Hash) | 	info, err := mr.GetInfo(p.Deb.Hash) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	p.Binary.Name = info.Result[0].Name | 	p.Deb.Name = info.Result[0].Name | ||||||
|  |  | ||||||
| 	p.Repo.Archive = info.Result[0].ArchiveName | 	p.Repo.Archive = info.Result[0].ArchiveName | ||||||
| 	p.Repo.Snapshot = info.Result[0].FirstSeen | 	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 | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ func TestSourcePackageVersions(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func TestPackages(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)$`) | 		`^linux-(image|headers)-[0-9\.\-]*-(amd64|amd64-unsigned)$`) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Fatal(err) | 		t.Fatal(err) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user