1
0

feat: match only stable debian releases, backports, and updates

This commit is contained in:
dump_stack() 2023-05-28 11:59:44 +00:00
parent dce7546dd2
commit 013fb42350
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
3 changed files with 38 additions and 25 deletions

View File

@ -133,6 +133,18 @@ func (cn Release) String() string {
func ReleaseFromString(s string) (r Release) {
switch strings.ToLower(s) {
case "1", "buzz":
r = Buzz
case "2", "hamm":
r = Hamm
case "3", "woody":
r = Woody
case "4", "etch":
r = Etch
case "5", "lenny":
r = Lenny
case "6", "squeeze":
r = Squeeze
case "7", "wheezy":
r = Wheezy
case "8", "jessie":

View File

@ -125,24 +125,7 @@ func getDebianKernel(version string) (dk DebianKernel, err error) {
s := strings.Replace(dk.Image.Name, "linux-image-", "", -1)
dk.Version.ABI = strings.Replace(s, "-amd64", "", -1)
p := dk.Image
repos, err := metasnap.GetRepos(p.Repo.Archive, p.Name, p.Arch, version)
if err != nil {
flog.Debug().Err(err).Msg("ignore metasnap")
err = nil
}
for _, repo := range repos {
for _, release := range ReleaseStrings[1:] {
if strings.Contains(repo.Suite, release) {
dk.Release = ReleaseFromString(release)
break
}
}
if dk.Release != None {
break
}
}
dk.Release = getRelease(dk.Image)
if dk.Release == None {
flog.Warn().Msg("release not found")
} else {
@ -152,6 +135,25 @@ func getDebianKernel(version string) (dk DebianKernel, err error) {
return
}
func getRelease(p snapshot.Package) Release {
repos, err := metasnap.GetRepos(p.Repo.Archive, p.Name, p.Arch, p.Version)
if err != nil {
log.Debug().Err(err).Msg("metasnap")
return None
}
for _, repo := range repos {
for _, rel := range ReleaseStrings[1:] {
switch repo.Suite {
case rel, rel + "-backports", rel + "-updates":
return ReleaseFromString(rel)
}
}
}
return None
}
// GetCachedKernel by deb package name
func getCachedKernel(deb string) (dk DebianKernel, err error) {
c, err := NewCache(CachePath)

View File

@ -4,17 +4,16 @@ import (
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/stretchr/testify/assert"
)
func TestGetDebianKernel(t *testing.T) {
dk, err := getDebianKernel("4.17.14-1")
if err != nil {
t.Fatal(err)
}
assert := assert.New(t)
if dk.Version.ABI != "4.17.0-2" {
t.Fatalf("wrong abi")
}
dk, err := getDebianKernel("4.6.4-1")
assert.Nil(err)
assert.Equal(getRelease(dk.Image), Stretch)
t.Logf("%s", spew.Sdump(dk))
}