1
0

feat: add update for debian release

This commit is contained in:
dump_stack() 2023-05-29 08:38:53 +00:00
parent a3170ada69
commit 443d23bd67
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
3 changed files with 38 additions and 10 deletions

View File

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

View File

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

View File

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