From b49076db7cb15f710bd9e9919ac1fc3e7be50496 Mon Sep 17 00:00:00 2001 From: Roman Vynar Date: Mon, 6 May 2024 16:47:37 +0300 Subject: [PATCH] Fix repo tag count when a repo name is a prefix for another repo name(s) --- CHANGELOG.md | 4 ++++ registry/client.go | 6 +++--- web.go | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a14706f..c713dde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +## UNRELEASED + +* Fix repo tag count when a repo name is a prefix for another repo name(s) + ## 0.10.1 (2024-04-19) * Rename cmd flag `-purge-from-repos` to `-purge-include-repos` to purge tags only for the specified repositories. diff --git a/registry/client.go b/registry/client.go index c17d2fe..b8a7962 100644 --- a/registry/client.go +++ b/registry/client.go @@ -272,8 +272,8 @@ func (c *Client) GetImageCreated(imageRef string) time.Time { return cfg.Created.Time } -// TagCounts return map with tag counts according to the provided list of repos/sub-repos etc. -func (c *Client) TagCounts(repoPath string, repos []string) map[string]int { +// SubRepoTagCounts return map with tag counts according to the provided list of repos/sub-repos etc. +func (c *Client) SubRepoTagCounts(repoPath string, repos []string) map[string]int { counts := map[string]int{} for _, r := range repos { subRepo := r @@ -281,7 +281,7 @@ func (c *Client) TagCounts(repoPath string, repos []string) map[string]int { subRepo = repoPath + "/" + r } for k, v := range c.tagCounts { - if strings.HasPrefix(k, subRepo) { + if k == subRepo || strings.HasPrefix(k, subRepo+"/") { counts[subRepo] = counts[subRepo] + v } } diff --git a/web.go b/web.go index cf86d20..eb4fada 100644 --- a/web.go +++ b/web.go @@ -76,7 +76,7 @@ func (a *apiClient) viewCatalog(c echo.Context) error { } data.Set("repos", repos) data.Set("isCatalogReady", a.client.IsCatalogReady()) - data.Set("tagCounts", a.client.TagCounts(repoPath, repos)) + data.Set("tagCounts", a.client.SubRepoTagCounts(repoPath, repos)) data.Set("tags", tags) if repoPath != "" && (len(repos) > 0 || len(tags) > 0) { // Do not show events in the root of catalog.