Implement refetch
This commit is contained in:
parent
3d2b8b7d2a
commit
efbdc9db36
27
debian.go
27
debian.go
@ -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)
|
||||
|
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user