From 0aa5fbb6c5997867e3a160fdf95e3dab1a6f1e59 Mon Sep 17 00:00:00 2001 From: Eric Phillips Date: Fri, 29 May 2026 09:42:26 -0600 Subject: [PATCH] change match method for cached pkgs --- internal/repomaint/db.go | 10 ++++------ internal/repomaint/repomaint.go | 5 ++--- internal/repomaint/repomaint_test.go | 8 ++++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/internal/repomaint/db.go b/internal/repomaint/db.go index 859bc92..87ac4e8 100644 --- a/internal/repomaint/db.go +++ b/internal/repomaint/db.go @@ -10,7 +10,6 @@ import ( "os" "path/filepath" "slices" - "strings" ) 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" { continue } - if !slices.Contains(pkgs, filepath.Dir(hdr.Name)) { - continue - } pkgName, pkgFile, err := parseDesc(db) if err != nil { slog.Warn("failed to parse desc file", "pkg", hdr.Name, "err", err) continue } + if !slices.Contains(pkgs, pkgFile) { + continue + } pkgMap[pkgName] = pkgFile } @@ -115,8 +114,7 @@ func (r *RepoSync) getCachedPkgs(repo string) ([]string, error) { } var pkgs []string for _, f := range files { - pkg := strings.TrimSuffix(f.Name(), pkgSuffix) - pkgs = append(pkgs, pkg) + pkgs = append(pkgs, f.Name()) } return pkgs, nil diff --git a/internal/repomaint/repomaint.go b/internal/repomaint/repomaint.go index f840405..d8b7c3b 100644 --- a/internal/repomaint/repomaint.go +++ b/internal/repomaint/repomaint.go @@ -11,9 +11,8 @@ import ( ) const ( - repoArch = "os/x86_64" - dbSuffix = ".db.tar.gz" - pkgSuffix = "-x86_64.pkg.tar.zst" + repoArch = "os/x86_64" + dbSuffix = ".db.tar.gz" ) type CacheClient interface { diff --git a/internal/repomaint/repomaint_test.go b/internal/repomaint/repomaint_test.go index 1f161d2..83de899 100644 --- a/internal/repomaint/repomaint_test.go +++ b/internal/repomaint/repomaint_test.go @@ -70,7 +70,7 @@ func TestParseDesc(t *testing.T) { }) } -func TestCachedFiles(t *testing.T) { +func TestGetCachedFiles(t *testing.T) { testFiles := []string{ "linux-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") require.NoError(t, err) - assert.Contains(t, cachedFiles, "linux") - assert.Contains(t, cachedFiles, "gcc-rust") - assert.Contains(t, cachedFiles, "linux-api-headers") + assert.Contains(t, cachedFiles, "linux-x86_64.pkg.tar.zst") + assert.Contains(t, cachedFiles, "gcc-rust-x86_64.pkg.tar.zst") + assert.Contains(t, cachedFiles, "linux-api-headers-x86_64.pkg.tar.zst") } func TestBuildMap(t *testing.T) {