1
0

feat: support getting cached kernels

This commit is contained in:
dump_stack() 2023-05-13 19:48:01 +00:00
parent 0bf2acb043
commit 29010b2a1b
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC

View File

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