1
0

Implement refetch

This commit is contained in:
dump_stack() 2023-05-12 00:07:51 +00:00
parent 3d2b8b7d2a
commit efbdc9db36
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 32 additions and 10 deletions

View File

@ -1,6 +1,8 @@
package main
import (
"time"
"github.com/rs/zerolog/log"
"code.dumpstack.io/tools/out-of-tree/distro/debian"
@ -13,6 +15,7 @@ type DebianCmd struct {
type DebianCacheCmd struct {
Path string `help:"path to cache" default:"debian.cache"`
Refetch int `help:"days before refetch versions without deb package" default:"7"`
}
func (cmd *DebianCacheCmd) Run() (err error) {
@ -33,20 +36,32 @@ func (cmd *DebianCacheCmd) Run() (err error) {
slog := log.With().Str("version", version).Logger()
slog.Info().Msgf("%03d/%03d", i, len(versions))
_, err = c.Get(version)
if err == nil {
var dk debian.DebianKernel
dk, err = c.Get(version)
if err == nil && !dk.Internal.Invalid {
slog.Info().Msgf("found in cache")
continue
}
var dk debian.DebianKernel
if dk.Internal.Invalid {
refetch := dk.Internal.LastFetch.AddDate(0, 0, cmd.Refetch)
if refetch.After(time.Now()) {
slog.Info().Msgf("refetch at %v", refetch)
continue
}
}
dk, err = debian.GetDebianKernel(version)
if err != nil {
if err == debian.ErrNoBinaryPackages {
slog.Warn().Err(err).Msg("")
continue
} else if err != nil {
} else {
slog.Error().Err(err).Msg("get debian kernel")
continue
}
dk.Internal.Invalid = true
dk.Internal.LastFetch = time.Now()
}
err = c.Put(dk)

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strings"
"time"
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
)
@ -23,6 +24,12 @@ type DebianKernel struct {
Version DebianKernelVersion
Image snapshot.Package
Headers snapshot.Package
// FIXME There is a better way
Internal struct {
Invalid bool
LastFetch time.Time
}
}
var (