1
0

feat: support multiple headers packages

This commit is contained in:
dump_stack() 2023-05-14 11:06:54 +00:00
parent 6b8d97be39
commit 6bb0da5082
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
4 changed files with 26 additions and 28 deletions

View File

@ -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:

View File

@ -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,12 +113,17 @@ 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
}
for _, h := range tmpdk.Headers {
if deb == h.Deb.Name {
dk = tmpdk
return
}
}
}
return
}

View File

@ -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)
}
}

View File

@ -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 {