From 6bb0da50821dcb08e9674aee18c649b4beb82f2b Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sun, 14 May 2023 11:06:54 +0000 Subject: [PATCH] feat: support multiple headers packages --- .github/workflows/debian-cache.yml | 4 ++- distro/debian/kernel.go | 40 ++++++++++--------------- distro/debian/snapshot/snapshot_test.go | 6 ++-- kernel/kernel.go | 4 ++- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/.github/workflows/debian-cache.yml b/.github/workflows/debian-cache.yml index fd21b41..6b8d7ee 100644 --- a/.github/workflows/debian-cache.yml +++ b/.github/workflows/debian-cache.yml @@ -7,7 +7,9 @@ on: push: paths: - '.github/workflows/debian-cache.yml' - - 'distro/debian/**' + - 'distro/debian/snapshot/**' + - 'distro/debian/cache.go' + - 'distro/debian/kernel.go' jobs: debian-cache: diff --git a/distro/debian/kernel.go b/distro/debian/kernel.go index 9f57ddd..842001b 100644 --- a/distro/debian/kernel.go +++ b/distro/debian/kernel.go @@ -2,7 +2,6 @@ package debian import ( "errors" - "fmt" "strings" "time" @@ -25,7 +24,7 @@ type DebianKernelVersion struct { type DebianKernel struct { Version DebianKernelVersion Image snapshot.Package - Headers snapshot.Package + Headers []snapshot.Package Dependencies []snapshot.Package // FIXME There is a better way @@ -44,7 +43,7 @@ var ( func GetDebianKernel(version string) (dk DebianKernel, err error) { dk.Version.Package = version - regex := `^linux-(image|headers)-[a-z+~0-9\.\-]*-(amd64|amd64-unsigned)$` + regex := `^linux-(image|headers)-[a-z+~0-9\.\-]*-(common|amd64|amd64-unsigned)$` filter := []string{ "rt-amd64", @@ -61,20 +60,6 @@ func GetDebianKernel(version string) (dk DebianKernel, err error) { if len(packages) == 0 { err = ErrNoBinaryPackages return - } else if len(packages) == 1 { - if strings.Contains(packages[0].Name, "image") { - err = ErrNoHeadersPackage - return - } else if strings.Contains(packages[0].Name, "headers") { - err = ErrNoImagePackage - return - } else { - err = fmt.Errorf("wtf? %v", packages[0].Name) - return - } - } else if len(packages) > 2 { - err = errors.New("more than two binary packages found") - return } var imageFound, headersFound bool @@ -84,21 +69,23 @@ func GetDebianKernel(version string) (dk DebianKernel, err error) { dk.Image = p } else if strings.Contains(p.Name, "headers") { headersFound = true - dk.Headers = p + dk.Headers = append(dk.Headers, p) + } else { + dk.Dependencies = append(dk.Dependencies, p) } } if !imageFound { - err = errors.New("image not found") + err = ErrNoImagePackage return } if !headersFound { - err = errors.New("headers not found") + err = ErrNoHeadersPackage return } - s := strings.Replace(dk.Headers.Name, "linux-headers-", "", -1) + s := strings.Replace(dk.Image.Name, "linux-image-", "", -1) dk.Version.ABI = strings.Replace(s, "-amd64", "", -1) return @@ -126,10 +113,15 @@ func GetCachedKernel(deb string) (dk DebianKernel, err error) { continue } - switch deb { - case tmpdk.Image.Deb.Name, tmpdk.Headers.Deb.Name: + if deb == tmpdk.Image.Deb.Name { dk = tmpdk - return + } + + for _, h := range tmpdk.Headers { + if deb == h.Deb.Name { + dk = tmpdk + return + } } } diff --git a/distro/debian/snapshot/snapshot_test.go b/distro/debian/snapshot/snapshot_test.go index d512705..f5dd3c9 100644 --- a/distro/debian/snapshot/snapshot_test.go +++ b/distro/debian/snapshot/snapshot_test.go @@ -20,7 +20,7 @@ func TestSourcePackageVersions(t *testing.T) { func TestPackages(t *testing.T) { packages, err := Packages("linux", "3.16.5-1", "amd64", - `^linux-(image|headers)-[0-9\.\-]*-(amd64|amd64-unsigned)$`, + `^linux-(image|headers)-[0-9\.\-]*-(common|amd64|amd64-unsigned)$`, []string{}) if err != nil { t.Fatal(err) @@ -30,5 +30,7 @@ func TestPackages(t *testing.T) { t.Fatal(errors.New("empty response")) } - t.Log(packages) + for _, pkg := range packages { + t.Logf("%#v", pkg) + } } diff --git a/kernel/kernel.go b/kernel/kernel.go index e8bd520..7c9ebbc 100644 --- a/kernel/kernel.go +++ b/kernel/kernel.go @@ -393,6 +393,8 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e "/boot/initramfs-%s.img %s", version, version) } case config.Debian: + // TODO move to distro/debian/ + var dk debian.DebianKernel dk, err = debian.GetCachedKernel(pkgname + ".deb") if err != nil { @@ -411,7 +413,7 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e pkgs := []snapshot.Package{dk.Image} if headers { - pkgs = append(pkgs, dk.Headers) + pkgs = append(pkgs, dk.Headers...) } for _, pkg := range pkgs {