1
0

feat: add limit amount of kernels to fetch

This commit is contained in:
dump_stack() 2023-05-28 20:37:05 +00:00
parent 4db10c66dc
commit 487b9c520d
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
3 changed files with 30 additions and 7 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
run: ./out-of-tree --log-level=trace distro debian cache --refetch=0 --limit=64
- name: Install s3cmd
run: sudo apt install s3cmd

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"math"
"os"
"path/filepath"
"regexp"
@ -30,6 +31,7 @@ type DebianCmd struct {
Cache DebianCacheCmd `cmd:"" help:"populate cache"`
Fetch DebianFetchCmd `cmd:"" help:"download deb packages"`
Limit int `help:"limit amount of kernels to fetch"`
Regex string `help:"match deb pkg names by regex" default:".*"`
}
@ -47,7 +49,11 @@ func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) {
log.Info().Msg("Fetching kernels...")
kernels, err := debian.GetKernels()
if dcmd.Limit == 0 {
dcmd.Limit = math.MaxInt32
}
kernels, err := debian.GetKernelsWithLimit(dcmd.Limit)
if err != nil {
log.Error().Err(err).Msg("")
return
@ -152,7 +158,11 @@ func (cmd *DebianFetchCmd) Run(dcmd *DebianCmd) (err error) {
log.Info().Msg("will not download packages that exist on the mirror")
log.Info().Msg("use --ignore-mirror if you really need it")
kernels, err := debian.GetKernels()
if dcmd.Limit == 0 {
dcmd.Limit = math.MaxInt32
}
kernels, err := debian.GetKernelsWithLimit(dcmd.Limit)
if err != nil {
log.Error().Err(err).Msg("")
return

View File

@ -2,6 +2,7 @@ package debian
import (
"errors"
"math"
"sort"
"strings"
"time"
@ -260,7 +261,7 @@ func findKbuild(versions []string, kpkgver string) (
}
func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string,
version string) (kernels []DebianKernel) {
version string) (kernels []DebianKernel, fromcache bool) {
var dk DebianKernel
dks, err := c.Get(version)
@ -269,6 +270,7 @@ func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string,
if !dk.Internal.Invalid {
slog.Trace().Msgf("found in cache")
kernels = append(kernels, dk)
fromcache = true
return
}
}
@ -336,7 +338,9 @@ var (
RefetchDays int = 14
)
func GetKernels() (kernels []DebianKernel, err error) {
// 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) {
if CachePath == "" {
CachePath = config.File("debian.cache")
log.Debug().Msgf("Use default kernels cache path: %s", CachePath)
@ -381,10 +385,19 @@ func GetKernels() (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 := getKernelsByVersion(slog, c, toolsVersions, version)
vkernels, fromcache := getKernelsByVersion(slog, c, toolsVersions, version)
kernels = append(kernels, vkernels...)
if !fromcache {
limit--
}
if limit <= 0 {
return
}
}
return
}
func GetKernels() (kernels []DebianKernel, err error) {
return GetKernelsWithLimit(math.MaxInt32)
}