change match method for cached pkgs

This commit is contained in:
2026-05-29 09:42:26 -06:00
parent 9aa79753ff
commit 0aa5fbb6c5
3 changed files with 10 additions and 13 deletions
+4 -6
View File
@@ -10,7 +10,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"slices" "slices"
"strings"
) )
func (r *RepoSync) buildMap(repo string) (map[string]string, error) { func (r *RepoSync) buildMap(repo string) (map[string]string, error) {
@@ -43,14 +42,14 @@ func (r *RepoSync) buildMap(repo string) (map[string]string, error) {
if filepath.Base(hdr.Name) != "desc" { if filepath.Base(hdr.Name) != "desc" {
continue continue
} }
if !slices.Contains(pkgs, filepath.Dir(hdr.Name)) {
continue
}
pkgName, pkgFile, err := parseDesc(db) pkgName, pkgFile, err := parseDesc(db)
if err != nil { if err != nil {
slog.Warn("failed to parse desc file", "pkg", hdr.Name, "err", err) slog.Warn("failed to parse desc file", "pkg", hdr.Name, "err", err)
continue continue
} }
if !slices.Contains(pkgs, pkgFile) {
continue
}
pkgMap[pkgName] = pkgFile pkgMap[pkgName] = pkgFile
} }
@@ -115,8 +114,7 @@ func (r *RepoSync) getCachedPkgs(repo string) ([]string, error) {
} }
var pkgs []string var pkgs []string
for _, f := range files { for _, f := range files {
pkg := strings.TrimSuffix(f.Name(), pkgSuffix) pkgs = append(pkgs, f.Name())
pkgs = append(pkgs, pkg)
} }
return pkgs, nil return pkgs, nil
-1
View File
@@ -13,7 +13,6 @@ import (
const ( const (
repoArch = "os/x86_64" repoArch = "os/x86_64"
dbSuffix = ".db.tar.gz" dbSuffix = ".db.tar.gz"
pkgSuffix = "-x86_64.pkg.tar.zst"
) )
type CacheClient interface { type CacheClient interface {
+4 -4
View File
@@ -70,7 +70,7 @@ func TestParseDesc(t *testing.T) {
}) })
} }
func TestCachedFiles(t *testing.T) { func TestGetCachedFiles(t *testing.T) {
testFiles := []string{ testFiles := []string{
"linux-x86_64.pkg.tar.zst", "linux-x86_64.pkg.tar.zst",
"gcc-rust-x86_64.pkg.tar.zst", "gcc-rust-x86_64.pkg.tar.zst",
@@ -91,9 +91,9 @@ func TestCachedFiles(t *testing.T) {
cachedFiles, err := rs.getCachedPkgs("core") cachedFiles, err := rs.getCachedPkgs("core")
require.NoError(t, err) require.NoError(t, err)
assert.Contains(t, cachedFiles, "linux") assert.Contains(t, cachedFiles, "linux-x86_64.pkg.tar.zst")
assert.Contains(t, cachedFiles, "gcc-rust") assert.Contains(t, cachedFiles, "gcc-rust-x86_64.pkg.tar.zst")
assert.Contains(t, cachedFiles, "linux-api-headers") assert.Contains(t, cachedFiles, "linux-api-headers-x86_64.pkg.tar.zst")
} }
func TestBuildMap(t *testing.T) { func TestBuildMap(t *testing.T) {