2023-05-11 20:08:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-05-12 00:07:51 +00:00
|
|
|
"time"
|
|
|
|
|
2023-05-11 20:08:08 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
|
|
|
"code.dumpstack.io/tools/out-of-tree/distro/debian"
|
|
|
|
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DebianCmd struct {
|
|
|
|
Cache DebianCacheCmd `cmd:"" help:"populate cache"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type DebianCacheCmd struct {
|
2023-05-12 00:07:51 +00:00
|
|
|
Path string `help:"path to cache" default:"debian.cache"`
|
|
|
|
Refetch int `help:"days before refetch versions without deb package" default:"7"`
|
2023-05-11 20:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *DebianCacheCmd) Run() (err error) {
|
|
|
|
c, err := debian.NewCache(cmd.Path)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("cache")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
versions, err := snapshot.SourcePackageVersions("linux")
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("get source package versions")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, version := range versions {
|
|
|
|
slog := log.With().Str("version", version).Logger()
|
|
|
|
slog.Info().Msgf("%03d/%03d", i, len(versions))
|
|
|
|
|
2023-05-12 00:07:51 +00:00
|
|
|
var dk debian.DebianKernel
|
|
|
|
|
|
|
|
dk, err = c.Get(version)
|
|
|
|
if err == nil && !dk.Internal.Invalid {
|
2023-05-11 20:08:08 +00:00
|
|
|
slog.Info().Msgf("found in cache")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-05-12 00:07:51 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-11 20:08:08 +00:00
|
|
|
dk, err = debian.GetDebianKernel(version)
|
2023-05-12 00:07:51 +00:00
|
|
|
if err != nil {
|
|
|
|
if err == debian.ErrNoBinaryPackages {
|
|
|
|
slog.Warn().Err(err).Msg("")
|
|
|
|
} else {
|
|
|
|
slog.Error().Err(err).Msg("get debian kernel")
|
|
|
|
}
|
|
|
|
|
|
|
|
dk.Internal.Invalid = true
|
|
|
|
dk.Internal.LastFetch = time.Now()
|
2023-05-11 20:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.Put(dk)
|
|
|
|
if err != nil {
|
|
|
|
slog.Error().Err(err).Msg("put to cache")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
slog.Info().Msgf("%s cached", version)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|