1
0

feat: add --dump to dump cache

This commit is contained in:
dump_stack() 2023-05-17 12:33:44 +00:00
parent 7e3f02f3a9
commit 950cee6df0
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC

View File

@ -2,12 +2,14 @@ package main
import ( import (
"context" "context"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"time" "time"
"github.com/cavaliergopher/grab/v3" "github.com/cavaliergopher/grab/v3"
"github.com/davecgh/go-spew/spew"
"github.com/remeh/sizedwaitgroup" "github.com/remeh/sizedwaitgroup"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -25,14 +27,17 @@ type DistroCmd struct {
type DebianCmd struct { type DebianCmd struct {
Cache DebianCacheCmd `cmd:"" help:"populate cache"` Cache DebianCacheCmd `cmd:"" help:"populate cache"`
Fetch DebianFetchCmd `cmd:"" help:"download deb packages"` Fetch DebianFetchCmd `cmd:"" help:"download deb packages"`
Regex string `help:"match deb pkg names by regex" default:".*"`
} }
type DebianCacheCmd struct { type DebianCacheCmd struct {
Path string `help:"path to cache"` Path string `help:"path to cache"`
Refetch int `help:"days before refetch versions without deb package" default:"7"` Refetch int `help:"days before refetch versions without deb package" default:"7"`
Dump bool `help:"dump cache"`
} }
func (cmd *DebianCacheCmd) Run() (err error) { func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) {
if cmd.Path != "" { if cmd.Path != "" {
debian.CachePath = cmd.Path debian.CachePath = cmd.Path
} }
@ -40,20 +45,32 @@ func (cmd *DebianCacheCmd) Run() (err error) {
log.Info().Msg("Fetching kernels...") log.Info().Msg("Fetching kernels...")
_, err = debian.GetKernels() kernels, err := debian.GetKernels()
if err != nil { if err != nil {
log.Error().Err(err).Msg("") log.Error().Err(err).Msg("")
return return
} }
if cmd.Dump {
re, err := regexp.Compile(dcmd.Regex)
if err != nil {
log.Fatal().Err(err).Msg("regex")
}
for _, kernel := range kernels {
if !re.MatchString(kernel.Image.Deb.Name) {
continue
}
fmt.Println(spew.Sdump(kernel))
}
}
log.Info().Msg("Success") log.Info().Msg("Success")
return return
} }
type DebianFetchCmd struct { type DebianFetchCmd struct {
Path string `help:"path to download directory" type:"existingdir" default:"./"` Path string `help:"path to download directory" type:"existingdir" default:"./"`
Regexp string `help:"match deb pkg names by regexp" default:".*"`
IgnoreMirror bool `help:"ignore check if packages on the mirror"` IgnoreMirror bool `help:"ignore check if packages on the mirror"`
Max int `help:"do not download more than X" default:"100500"` Max int `help:"do not download more than X" default:"100500"`
@ -124,12 +141,15 @@ func (cmd *DebianFetchCmd) fetch(pkg snapshot.Package) {
cmd.Max-- cmd.Max--
} }
func (cmd *DebianFetchCmd) Run() (err error) { func (cmd *DebianFetchCmd) Run(dcmd *DebianCmd) (err error) {
re, err := regexp.Compile(cmd.Regexp) re, err := regexp.Compile(dcmd.Regex)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("regexp") log.Fatal().Err(err).Msg("regex")
} }
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() kernels, err := debian.GetKernels()
if err != nil { if err != nil {
log.Error().Err(err).Msg("") log.Error().Err(err).Msg("")