From 29010b2a1b434002a7e9e60516b8fcf7f63f1807 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sat, 13 May 2023 19:48:01 +0000 Subject: [PATCH] feat: support getting cached kernels --- distro/debian/kernel.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/distro/debian/kernel.go b/distro/debian/kernel.go index e083339..36f41d9 100644 --- a/distro/debian/kernel.go +++ b/distro/debian/kernel.go @@ -103,6 +103,38 @@ func GetDebianKernel(version string) (dk DebianKernel, err error) { return } +// GetCachedKernel by deb package name +func GetCachedKernel(deb string) (dk DebianKernel, err error) { + c, err := NewCache(CachePath) + if err != nil { + log.Error().Err(err).Msg("cache") + return + } + defer c.Close() + + versions, err := c.GetVersions() + if err != nil { + log.Error().Err(err).Msg("get source package versions from cache") + return + } + + for _, version := range versions { + var tmpdk DebianKernel + tmpdk, err = c.Get(version) + if err != nil { + continue + } + + switch deb { + case tmpdk.Image.Deb.Name, tmpdk.Headers.Deb.Name: + dk = tmpdk + return + } + } + + return +} + func GetKernels(c *Cache, refetchDays int) (kernels []DebianKernel, err error) { versions, err := snapshot.SourcePackageVersions("linux") if err != nil { @@ -110,6 +142,12 @@ func GetKernels(c *Cache, refetchDays int) (kernels []DebianKernel, err error) { return } + err = c.PutVersions(versions) + if err != nil { + log.Error().Err(err).Msg("put source package versions to cache") + return + } + for i, version := range versions { slog := log.With().Str("version", version).Logger() slog.Debug().Msgf("%03d/%03d", i, len(versions))