From 443d23bd67426c357c9dd24ab0f856f3757299f1 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Mon, 29 May 2023 08:38:53 +0000 Subject: [PATCH] feat: add update for debian release --- .github/workflows/debian-cache.yml | 2 +- distro.go | 16 +++++++++++----- distro/debian/kernel.go | 30 ++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.github/workflows/debian-cache.yml b/.github/workflows/debian-cache.yml index 32ab3ef..01cc9d3 100644 --- a/.github/workflows/debian-cache.yml +++ b/.github/workflows/debian-cache.yml @@ -25,7 +25,7 @@ jobs: run: go build - name: Cache - run: ./out-of-tree --log-level=trace distro debian cache --refetch=0 --limit=128 + run: ./out-of-tree --log-level=trace distro debian cache --refetch=0 --limit=128 --update-release - name: Install s3cmd run: sudo apt install s3cmd diff --git a/distro.go b/distro.go index 09ee123..5a69342 100644 --- a/distro.go +++ b/distro.go @@ -36,9 +36,10 @@ type DebianCmd struct { } type DebianCacheCmd struct { - Path string `help:"path to cache"` - Refetch int `help:"days before refetch versions without deb package" default:"7"` - Dump bool `help:"dump cache"` + Path string `help:"path to cache"` + Refetch int `help:"days before refetch versions without deb package" default:"7"` + UpdateRelease bool `help:"update release data"` + Dump bool `help:"dump cache"` } func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) { @@ -53,7 +54,12 @@ func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) { dcmd.Limit = math.MaxInt32 } - kernels, err := debian.GetKernelsWithLimit(dcmd.Limit) + mode := debian.NoMode + if cmd.UpdateRelease { + mode = debian.UpdateRelease + } + + kernels, err := debian.GetKernelsWithLimit(dcmd.Limit, mode) if err != nil { log.Error().Err(err).Msg("") return @@ -162,7 +168,7 @@ func (cmd *DebianFetchCmd) Run(dcmd *DebianCmd) (err error) { dcmd.Limit = math.MaxInt32 } - kernels, err := debian.GetKernelsWithLimit(dcmd.Limit) + kernels, err := debian.GetKernelsWithLimit(dcmd.Limit, debian.NoMode) if err != nil { log.Error().Err(err).Msg("") return diff --git a/distro/debian/kernel.go b/distro/debian/kernel.go index 2d10d11..6a95134 100644 --- a/distro/debian/kernel.go +++ b/distro/debian/kernel.go @@ -261,7 +261,8 @@ func findKbuild(versions []string, kpkgver string) ( } func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string, - version string) (kernels []DebianKernel, fromcache bool) { + version string, mode GetKernelsMode) (kernels []DebianKernel, + fromcache bool) { var dk DebianKernel dks, err := c.Get(version) @@ -269,6 +270,18 @@ func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string, dk = dks[0] if !dk.Internal.Invalid { slog.Trace().Msgf("found in cache") + if dk.Release == None && mode&UpdateRelease != 0 { + slog.Debug().Msg("update release") + dk.Release = getRelease(dk.Image) + if dk.Release != None { + slog.Debug().Msg("update cache") + err = c.Put([]DebianKernel{dk}) + if err != nil { + slog.Error().Err(err).Msg("") + return + } + } + } kernels = append(kernels, dk) fromcache = true return @@ -338,9 +351,18 @@ var ( RefetchDays int = 14 ) +type GetKernelsMode int + +const ( + NoMode GetKernelsMode = iota + UpdateRelease +) + // GetKernelsWithLimit is workaround for testing and building the // first cache, which is heavily rate limited by snapshot.debian.org -func GetKernelsWithLimit(limit int) (kernels []DebianKernel, err error) { +func GetKernelsWithLimit(limit int, mode GetKernelsMode) (kernels []DebianKernel, + err error) { + if CachePath == "" { CachePath = config.File("debian.cache") log.Debug().Msgf("Use default kernels cache path: %s", CachePath) @@ -385,7 +407,7 @@ func GetKernelsWithLimit(limit int) (kernels []DebianKernel, err error) { for i, version := range versions { slog := log.With().Str("version", version).Logger() slog.Trace().Msgf("%03d/%03d", i, len(versions)) - vkernels, fromcache := getKernelsByVersion(slog, c, toolsVersions, version) + vkernels, fromcache := getKernelsByVersion(slog, c, toolsVersions, version, mode) kernels = append(kernels, vkernels...) if !fromcache { limit-- @@ -399,5 +421,5 @@ func GetKernelsWithLimit(limit int) (kernels []DebianKernel, err error) { } func GetKernels() (kernels []DebianKernel, err error) { - return GetKernelsWithLimit(math.MaxInt32) + return GetKernelsWithLimit(math.MaxInt32, NoMode) }