Implement match for Debian packages
This commit is contained in:
parent
b5d4bdd5f4
commit
43aa116682
@ -1,5 +1,15 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/config"
|
||||
)
|
||||
|
||||
type CodeName int
|
||||
|
||||
const (
|
||||
@ -23,3 +33,47 @@ var CodeNameStrings = [...]string{
|
||||
func (cn CodeName) String() string {
|
||||
return CodeNameStrings[cn]
|
||||
}
|
||||
|
||||
var (
|
||||
CachePath string
|
||||
RefetchDays int = 7
|
||||
)
|
||||
|
||||
func MatchImagePkg(km config.KernelMask) (pkgs []string, err error) {
|
||||
if CachePath == "" {
|
||||
var usr *user.User
|
||||
usr, err = user.Current()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
CachePath = usr.HomeDir + "/.out-of-tree/debian.cache"
|
||||
log.Debug().Msgf("Use default kernels cache path: %s", CachePath)
|
||||
} else {
|
||||
log.Debug().Msgf("Debian kernels cache path: %s", CachePath)
|
||||
}
|
||||
|
||||
c, err := NewCache(CachePath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("cache")
|
||||
return
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
kernels, err := GetKernels(c, RefetchDays)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("get kernels")
|
||||
return
|
||||
}
|
||||
|
||||
r := regexp.MustCompile(km.ReleaseMask)
|
||||
|
||||
for _, dk := range kernels {
|
||||
p := strings.Replace(dk.Image.Deb.Name, ".deb", "", -1)
|
||||
if r.MatchString(p) {
|
||||
pkgs = append(pkgs, p)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
20
distro/debian/debian_test.go
Normal file
20
distro/debian/debian_test.go
Normal file
@ -0,0 +1,20 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/config"
|
||||
)
|
||||
|
||||
func TestMatchImagePkg(t *testing.T) {
|
||||
km := config.KernelMask{ReleaseMask: "3.2.0-4"}
|
||||
|
||||
pkgs, err := MatchImagePkg(km)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(pkgs) == 0 {
|
||||
t.Fatal("no packages")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user